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

后端 未结 9 1528
天命终不由人
天命终不由人 2020-12-12 18:59

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

相关标签:
9条回答
  • 2020-12-12 19:26

    Let me try to help in the case that the original answer doesn't work for you. For ES 6.x try the code below, ignore_unmapped is deprecated.

    "sort" : [
           { "rating": {"order" : "desc" , "unmapped_type" : "long"} },
           { "price": {"order" : "asc" , "missing" : "_last" , "unmapped_type" : "long"} }
    ]
    

    More about sorting you can find on:

    https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html

    0 讨论(0)
  • 2020-12-12 19:27

    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.

    0 讨论(0)
  • 2020-12-12 19:27

    When we use below code, where added_on is date, what happens !! attribute text is analyzed, meaning it is broken up into distinct words when stored, and allows for free-text searches on one or more words in the field

    so there is "text" and "keyword" associated with fields, so if we need to use aggregation in the query, we need the field value in general the keyword.

    BEFORE
    
    "_source":{....}
    "query" : {...}
    "sort": [
    {
      "added_on": {
        "order": "desc"
      }
    }
    ]
    
    AFTER
    "_source":{....}
    "query" : {...}
    "sort": [
    {
      "added_on.keyword": {
        "order": "desc"
      }
    }
    ]
    
    0 讨论(0)
提交回复
热议问题