When adding sorting configuration for data in OpenSearch, I came across a situation where the data's field that I want to sort on had only null values. OpenSearch return an error that says [query_shard_exception] Reason: No mapping found for [MY_NULL_FIELD] in order to sort on
. That being said, if I add ONE value, then the sort functions as expected. Is there a way around this?
CodePudding user response:
You can define null_value
properties while configuring index mapping.
PUT my-index-000001
{
"mappings": {
"properties": {
"status_code": {
"type": "keyword",
"null_value": "NULL"
}
}
}
}
Please consider below while configuring null value.
The null_value needs to be the same data type as the field. For instance, a long field cannot have a string null_value.
CodePudding user response:
If field values are all null
in all documents, the field probably does not exist in the mapping. Using unmapped_type
in the sort query should work.
{
"sort": [
{
"some_missing_field": {
"order": "asc",
"unmapped_type" : "long"
}
}
]
}