3

I'm using elasticsearch 2.3.1, and trying to write a query to filter on _score field.

I need to check whether _score is not null.

Here is what i've tried:

REQUEST

POST /_search
{
  "from" : 0, "size" : 200,
  "query": {
        "bool": {
          "must": [
            {
              "term": {
                "_type": "monitor"
              }
            }
          ],
          "must_not": [
            {
              "term": {
                "_score": {
                  "value": null
                }
              }
            }
          ]
        }
  },
  "sort": {
    "TraceDateTime": {
      "order": "desc",
      "ignore_unmapped": "true"
    }
  }
}

RESPONSE

{
   "error": {
      "root_cause": [
         {
            "type": "query_parsing_exception",
            "reason": "No value specified for term query",
            "index": ".kibana",
            "line": 18,
            "col": 15
         },
         {
            "type": "query_parsing_exception",
            "reason": "No value specified for term query",
            "index": "monitors",
            "line": 18,
            "col": 15
         }
      ],
      "type": "search_phase_execution_exception",
      "reason": "all shards failed",
      "phase": "query",
      "grouped": true,
      "failed_shards": [
         {
            "shard": 0,
            "index": ".kibana",
            "node": "IjGeW1YgSiiUY1devzlAgQ",
            "reason": {
               "type": "query_parsing_exception",
               "reason": "No value specified for term query",
               "index": ".kibana",
               "line": 18,
               "col": 15
            }
         },
         {
            "shard": 0,
            "index": "monitors",
            "node": "IjGeW1YgSiiUY1devzlAgQ",
            "reason": {
               "type": "query_parsing_exception",
               "reason": "No value specified for term query",
               "index": "monitors",
               "line": 18,
               "col": 15
            }
         }
      ]
   },
   "status": 400
}
ohadinho
  • 6,894
  • 16
  • 71
  • 124
  • 2
    `_score` is a field from your mapping? Have you tried `"must_not": { "exists": { "field": "_score" } }`? – Andrei Stefan Apr 18 '16 at 07:26
  • 1. _score is a known field of each document (like _type, _index and so on..). it's not part of my mapping. 2. Your suggestion returns also _score = null documents – ohadinho Apr 18 '16 at 08:33
  • :-) that's not how it works, that's the score ES gives to each document given the search. You can't filter after score just like you do with other terms. Have you looked at [min_score](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-min-score.html)? – Andrei Stefan Apr 18 '16 at 08:35
  • Let's add something to the question : How to I get documents within range of _score ? – ohadinho Apr 18 '16 at 08:46
  • @AndreiStefan I get it. Thanks. So we must add "track_scores" : true to each search ? – ohadinho Apr 18 '16 at 08:48
  • What's your use case? Do you need scoring? Why are you bothered by the score being `null`? – Andrei Stefan Apr 18 '16 at 08:57
  • @AndreiStefan I do not need. Just want to learn about scoring. – ohadinho Apr 18 '16 at 08:59
  • 1
    Manipulating the score this way is not a common practice. The way you adjust the score is by indexing (and analyzing/tokenizing) the data in specific way and then using certain queries. After this, ES gives some scores to documents matching the query and gives you the results in specific sorting order. – Andrei Stefan Apr 18 '16 at 09:07

0 Answers0