Elasticsearch - Mapper_parsing_exception, Failed to Parse Field

We have recently faced issue with Elasticsearch field types and mapping, when if a field is mapped with a type other type can not be indexed for the same field. Elasticsearch indesing mechanism ristrict that. for example we have created a index named users and inserted a record with text type field name.

Second record we want to insert same field with another type per say object, it will raise exceptation mapper_parsing_exception, failed to parse field.

Because with insertation of first record the index will create a mapping and provide the field type text with second record insertation where the type is an object it will not match with the mapping and raise exceptation.

Simple Hack But Many pitfalls

Since by nature Elasticsearch doesn’t support above scenario, once the mapping is created and type is assigned to a field it will not allow indexing of other type. However in my case we have to store the data in elasticsearch engine, so converted the object to string and that worked. But it will not support query on the converted object and on client side also we will need to convert back to object type.

After converting the object to text it will indexed as a text field only and will look like a escaped string object.

Still investigating on better solution or way to work on this issue.