Auto detection of Data type

This is the mapping initially which I created, considering that Roll number will be limit to only numbers. But eventually as they are growing in the roll numbers are Alphanumeric and the data type is changed.
PUT student_info
"Percentage": {"type": "float"},
"Rank": {"type": "integer"},

This the 1st record I want to insert to the index student_info
This is getting indexed correctly
PUT student_info/_doc/1
"Percentage": 81.0,

This is giving error
PUT student_info/_doc/2
"Percentage": 83.0,

Error "reason": "failed to parse field [Roll_no] of type [integer] in document with id '2'. Preview of field's value: 'A123'"

What is the question?
If the mapping is number, other values will fail.
You need to change the mapping to type text.

If you are using dynamic mapping the first occurrence of a field will determine the mapping. As you have the Roll_no set to a number this is how it is getting mapped. As mentioned this will prevent documents with non-numeric values in that field from getting indexed as mappings can not be changed for existing indices and each field has to have a single mapping. If you know a field can have non-numeric values, format it as a string in the JSON document and it will get mapped as a string. You can also specify the mapping ahead of time through an index template.

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