What are the permissible conversions from JSON data types to a given mapping?

I'm running on a version of Elasticsearch that requires shared fields to have the same data type (version 2.4.5). I have dynamic mapping enabled.

I'm trying to guard against the mistake of inserting two objects with fields with the same name but different types. It seems that because of conversion of the JSON data types, the order of the inserts can lead either to an exception (which we'd expect) or a successful insert.

For example, consider these scenarios where we insert two documents, the first for object type A and the second for object type, they both have a field with the same name:
Scenario 1: for the first insert, the field is a long. for the second insert, the field is a boolean
Scenario 2: the order is flipped (boolean first)

In scenario 1, we get an mapping parsing exception on the second insert.
In scenario 2, there is no error because the system somehow converts the long into a boolean. However, what's strange is that the second inserted document still has a long for that field - that is, the value is stored as a long, not a boolean, even though the mapping specifies a boolean.

What's the right way to think about this sort of discrepancy? We want to guard against object B accidentally having the same name as object A but where the value gets converted or indexed in a way that we didn't expect.

Use a template!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.