Create the num
field as long with auto-mapping.
PUT coerce_test/_doc/1
{
"num": 1
}
By default, coerce is true. That means a string value which can be converted into a number, can be ingested.
PUT coerce_test/_doc/2
{
"num": "2"
}
Changing coerce of an existing field is possible
POST coerce_test/_mapping
{
"properties": {
"num": {
"type": "long",
"coerce": false
}
}
}
After that, string values will be rejected.
PUT coerce_test/_doc/3
{
"num": "3"
}
Rejected result:
{
"error" : {
"root_cause" : [
{
"type" : "mapper_parsing_exception",
"reason" : "failed to parse field [num] of type [long] in document with id '3'. Preview of field's value: '3'"
}
],
"type" : "mapper_parsing_exception",
"reason" : "failed to parse field [num] of type [long] in document with id '3'. Preview of field's value: '3'",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Long value passed as String"
}
},
"status" : 400
}