2

While querying, I am trying to get only documents whose normalized scores(_score divided by max_score) are above a certain threshold. Is there any way to do that? I tried using function score, but I am getting a SearchPhaseExecutionException.

My query using the sense plugin:

POST my_index/my_type/_search
{
    "query": {
      "min_score": 0.4,

      "function_score" : {
         "query" :{
            "query_string": { "_all": "test"}
         },
         "functions": [
         {
            "script_score": {
                "script": "return _score / max_score;"
            }
         }
       ]
     }
   }
}

Exception trace: "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures

Oldskool
  • 34,211
  • 7
  • 53
  • 66

1 Answers1

0

Your query syntax is wrong. The "min_score" field should be outside the query block. And the syntax of "query_string" is also wrong. Refer doc.

Try this:

POST my_index/my_type/_search
{
    "min_score": 0.4,
    "query": {
      "function_score" : {
         "query" :{
            "query_string": {
                "query": "test",
                "fields": [
                    "_all"
                ]
            }
         },
         "functions": [
         {
            "script_score": {
                "script": "return _score / max_score;"
            }
         }
       ]
     }
   }
}

Moreover the error trace should be containing information about the failure. Generally you should be able to identify/get a direction for the errors from there.

Prabin Meitei
  • 1,920
  • 1
  • 13
  • 16