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

Yadu picture Yadu · Jun 11, 2013 · Viewed 74.3k times · Source

Elasticsearch throws a SearchParseException while parsing query if there are some documents found not containing field used in sort criteria.

SearchParseException: Parse Failure [No mapping found for [price] in order to sort on]

How can I successfully search these documents, even if some are missing the price field?

Answer

Yadu picture Yadu · Jun 11, 2013

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: