0

我正在尝试使用嵌套查询对查询结果进行重新评分,但出现以下异常,我认为这意味着重新评分不支持嵌套查询:

nested: ElasticsearchIllegalArgumentException[rescore doesn't support [path]];

是这样吗 ?

嵌套对象包含一个应该匹配的关键字段和一个应该用作分数的权重字段。这是查询:

POST myindex/_search
{
 "query" : {
    "match" : {
       "field1" : {
          "query" : "my_query_string",
          "type" : "boolean"
       }
    }
 },
 "rescore" : {
    "window_size" : 50,
    "query": {
      "nested": {
        "path": "path.to.nested.object",
        "score_mode" : "avg",
        "query": {
          "function_score": {
            "query":{
              "constant_score": {
                "query": { 
                  "match": {
                    "path.to.nested.object.key": "my_query_string"
                  }
                }
              }
            },
            "script_score": {
              "script": "doc['path.to.nested.object.weight'].value"
            }
          }
        }
      }
    }
  }
}
4

1 回答 1

2

您的查询中存在语法错误使用 re-score 您需要使用 rescore_query,因为query_rescorer是目前唯一支持的实现。

以下应该有效:

POST myindex/_search
{
   "query": {
      "match": {
         "field1": {
            "query": "my_query_string",
            "type": "boolean"
         }
      }
   },
   "rescore": {
      "window_size": 50,
      "query": {
         "rescore_query": {
            "nested": {
               "path": "path.to.nested.object",
               "score_mode": "avg",
               "query": {
                  "function_score": {
                     "query": {
                        "constant_score": {
                           "query": {
                              "match": {
                                 "path.to.nested.object.key": "my_query_string"
                              }
                           }
                        }
                     },
                     "script_score": {
                        "script": "doc['path.to.nested.object.weight'].value"
                     }
                  }
               }
            }
         }
      }
   }
}
于 2014-09-18T19:24:44.817 回答