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
{
"mappings":
{
"properties":
{
"Roll_no":{"type":"integer"},
"Percentage": {"type": "float"},
"Rank": {"type": "integer"},
"Name":{"type":"text"}
}
}
}
This the 1st record I want to insert to the index student_info
This is getting indexed correctly
PUT student_info/_doc/1
{
"Roll_no":123,
"Percentage": 81.0,
"Rank":4,
"Name":"Sam"
}
This is giving error
PUT student_info/_doc/2
{
"Roll_no":"A123",
"Percentage": 83.0,
"Rank":9,
"Name":"David"
}
Error "reason": "failed to parse field [Roll_no] of type [integer] in document with id '2'. Preview of field's value: 'A123'"
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.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.