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

4

1 回答 1

0

您的查询语法错误。“min_score”字段应该在查询块之外。并且“query_string”的语法也是错误的。参考文档

尝试这个:

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;"
            }
         }
       ]
     }
   }
}

此外,错误跟踪应该包含有关失败的信息。通常,您应该能够从那里识别/获取错误的方向。

于 2015-04-24T05:26:57.963 回答