No mapping found for field in order to sort on in ElasticSearch No mapping found for field in order to sort on in ElasticSearch elasticsearch elasticsearch

No mapping found for field in order to sort on in ElasticSearch


After digging more, I found the solution as given below. ignore_unmapped should be explicitly set to true in the sort clause.

"sort" : [       { "rating": {"order" : "desc" , "ignore_unmapped" : true} },       { "price": {"order" : "asc" , "missing" : "_last" , "ignore_unmapped" : true} }]

For further information have a look at the Elasticsearch references for:


For those looking for an example of both ignore_unmapped and unmapped_type please see my response here.

Note that "ignore_unmapped" is now deprecated in favor of "unmapped_type". This was done as part of #7039

From documentation: Before 1.4.0 there was the ignore_unmapped boolean parameter, which was not enough information to decide on the sort values to emit, and didn’t work for cross-index search. It is still supported but users are encouraged to migrate to the new unmapped_type instead.

By default, the search request will fail if there is no mapping associated with a field. The unmapped_type option allows to ignore fields that have no mapping and not sort by them. The value of this parameter is used to determine what sort values to emit. Here is an example of how it can be used:

{    "sort" : [        { "price" : {"unmapped_type" : "long"} },    ],    "query" : {        "term" : { "user" : "kimchy" }    }}

If any of the indices that are queried doesn’t have a mapping for price then Elasticsearch will handle it as if there was a mapping of type long, with all documents in this index having no value for this field.


Apparently ElasticSearch won't sort on null values. I was assuming it would treat null as being at the start or end (as with SQL ordering) but I believe it also triggers this error.

So if you see this error, you may need to ensure the sort attribute has a default value when it's sent to ElasticSearch.

I had this error with Rails+ElasticSearch+Tire because the sort column didn't have a default value, so was being sent to ES as null.

This issue indicates null values are handling, but it wasn't my experience. It's something worth trying anyway.