rescore是否支持嵌套查询?

时间:2014-09-18 12:56:01

标签: elasticsearch pyes

我试图使用嵌套查询重新调整我的查询结果,但是我得到以下异常,我相信这意味着rescore不支持嵌套查询:

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

1 个答案:

答案 0 :(得分:2)

您的查询中存在语法错误通过重新评分,您需要使用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"
                     }
                  }
               }
            }
         }
      }
   }
}