'Why does not working elasticsearch auto mapping when use number without quotes in json
When I try to initially POST data in index firs time
POST /my-test-index1/_doc/
{
"foo": {
"bar": [ "99.31.99.33", 862 ]
}
}
i receive error
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "mapper [user.id] cannot be changed from type [long] to [text]"
}
],
"type" : "illegal_argument_exception",
"reason" : "mapper [user.id] cannot be changed from type [long] to [text]"
},
"status" : 400
}
But if I initially post json with quotes numbers it's work, and next numbers without quotes also be work.
POST /my-test-index1/_doc/
{
"foo": {
"bar": [ "99.31.99.33", "862" ]
}
}
{
"_index" : "my-test-index1",
"_type" : "_doc",
"_id" : "OiyhdIABdQBSvDJuTJ4t",
"_version" : 1,
"result" : "created",
}
I know that initially post create mapping, but my question, why numbers in json without quotes doesn't work, not create right mapping when initially post
Solution 1:[1]
In first scenario, You are getting exception because array values are not same data type and index mapping is not created. You can check official documentation.
In Elasticsearch, there is no dedicated array data type. Any field can contain zero or more values by default, however, all values in the array must be of the same data type.
In second scenario, when initially post json with quotes numbers it's work because it will create index and set text type for bar field. Also, when you send other request with numbers without quotes, it will work as it consider all value of array as text and not integer.
You can use below API to check index mapping:
GET my-test-index1/_mapping
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sagar Patel |
