So I have a bunch of indices, rotated monthly, with two mappings - server, client. They both have a field user_id. In server, the user_id is a string, and in client, it is mostly a string, but in one months index, it got indexed as an integer.
When I try to do a terms aggregation on the user_id field, I get an error - ClassCastException[org.elasticsearch.search.aggregations.bucket.terms.StringTerms$Bucket cannot be cast to org.elasticsearch.search.aggregations.bucket.terms.LongTerms$Bucket]
When I query the monthly indices which have the correct mapping, I don't get the error.
This is fine, and expected.
But what I don't understand is why do I get this error even when I specify a mapping?
That is, /events-*/server/_search, and then do a terms aggregation on the user_id field.
Any chance you allow dynamic field mapping, the user id was not in the mapping and encountered for the first time?
Anyway, you can correct the problem by creating a new index with the correct mapping and using the reindex API to reindex the data. See index aliases and zero downtime on how to achieve this without affecting your users.
Now when I run a termsn aggregation on the user_id field, in /events/server, why does the mapping for user_id in client matter? Shouldn't they be independent of each other. I under that I'd get an error if I sent an query to /events.