No mapping found for sort field in ElasticSearch

Elasticsearch throws a SearchParseException when parsing the query if there are some documents found that do not contain the fields used in the sorting criteria.

SearchParseException: Parse Failure [No matching for [price] for sorting]

How can I successfully search for these documents, even if some of them do not have a price field?

+94
sorting mapping elasticsearch
Jun 11 '13 at 18:58
source share
7 answers

Having rummaged still, I found the solution given below. ignore_unmapped must 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 more information, take a look at Elasticsearch links for:

+102
Jun 11 '13 at 19:13
source share

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

Note that ignore_unmapped is now deprecated in favor of unmapped_type. It was made as part of # 7039

From the documentation: Prior to 1.4.0, there was a logical parameter ignore_unmapped, which had insufficient information to determine the sort values ​​for emission, and did not work for searching across multiple indexes. It is still supported, but users are advised to switch to the new unmapped_type file.

By default, the search query will not be executed if there is no mapping to the field. The unmapped_type option allows you to ignore fields that do not have a mapping, but are not sorted by them. The value of this parameter is used to determine the 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 requested indexes does not have a comparison for the price, then Elasticsearch will process it as if it were a display of type long, while all documents in this index did not matter for this field.

+35
Jun 15 '15 at 21:16
source share

ElasticSearch will apparently not sort the null values. I assumed that it would treat the null value as being at the beginning or at the end (as when ordering SQL), but I believe this also causes this error.

So, if you see this error, you may need to make sure that the sort attribute has a default value when submitted to ElasticSearch.

I had this error with Rails + ElasticSearch + Tire because the sort column did not have a default value, so it was sent to ES as null.

This problem indicates that null values ​​are being processed, but that was not my experience. It's still worth a try.

+3
Mar 29 '15 at 8:17
source share

I had the same problem (sorta; received some errors, but some results), but in my case my search returned in the root (without index), and the errors that I received were caused by the fact that the search / order also looked at the Kibana index.

Stupid mistake, but maybe this will help someone who gets here.

+2
Jan 03 '14 at 17:40
source share

Elasticsearch 6.4

just indicate the index and what is it in kiban

BEFORE

 GET /_search { "query": { "exists": { "field": "document_id" } }, "sort": [ { "document_id": { "order": "asc" }, "created_at": { "order": "desc" } } ] } 

AFTER

 GET /document-index/contact/_search (here) { "query": { "exists": { "field": "document_id" } }, "sort": [ { "document_id": { "order": "asc" }, "created_at": { "order": "desc" } } ] } 
+2
Sep 09 '18 at 2:40
source share

if you use ES 6.7

Try this

 sort : ["title.keyword:desc"] 
0
May 16 '19 at 13:22
source share

You can also use a script that gives you some flexibility:

 "sort" : { "_script" : { "type" : "number", "script" : { "lang": "painless", "source": "return !doc['price'].empty ? doc['price'].value : 0" }, "order" : "desc" } } 
0
Jul 04 '19 at 12:08 on
source share



All Articles