Elasticsearch提供[function_score]格式错误的查询,预期[END_OBJECT],但发现[FIELD_NAME]

时间:2018-08-27 12:14:00

标签: elasticsearch

我有一个使用function_score的查询,但出现错误,该查询格式不正确,可能会出现[END_OBJECT],但找到了[FIELD_NAME]。我检查了文档,找不到与此不正确或不一致的内容。我在这里没有在script_score中添加任何脚本,但是即使我尝试添加脚本,也出现了同样的问题。

{
  "from": 0,
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "filter": [
            {
              "bool": {
                "should": [
                  {
                    "bool": {
                      "must": [
                        {
                          "match": {
                            "address.area.area.raw": "Durbarmarg"
                          }
                        },
                        {
                          "match": {
                            "address.area.city.raw": "Kathmandu"
                          }
                        },
                        {
                          "match": {
                            "address.area.district.raw": "Kathmandu"
                          }
                        },
                        {
                          "match": {
                            "address.area.state.raw": "State-3"
                          }
                        },
                        {
                          "match": {
                            "address.area.country.raw": "Nepal"
                          }
                        }
                      ]
                    }
                  },
                  {
                    "nested": {
                      "inner_hits": {},
                      "path": "branchAddress",
                      "query": {
                        "bool": {
                          "must": [
                            {
                              "match": {
                                "branchAddress.area.area.raw": "Durbarmarg"
                              }
                            },
                            {
                              "match": {
                                "branchAddress.area.city.raw": "Kathmandu"
                              }
                            },
                            {
                              "match": {
                                "branchAddress.area.district.raw": "Kathmandu"
                              }
                            },
                            {
                              "match": {
                                "branchAddress.area.state.raw": "State-3"
                              }
                            },
                            {
                              "match": {
                                "branchAddress.area.country.raw": "Nepal"
                              }
                            }
                          ]
                        }
                      }
                    }
                  }
                ]
              }
            }
          ],
          "must": [
            {
              "term": {
                "sub_categories.raw": "Restaurant"
              }
            }
          ],
          "must_not": [],
          "should": []
        }
      }
    },
    "script_score": {}
  },
  "size": 10
}

错误如下:

raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: TransportError(400, 'parsing_exception', '[function_score] malformed query, expected [END_OBJECT] but found [FIELD_NAME]')

1 个答案:

答案 0 :(得分:0)

script_score部分的位置不正确,它必须是内部query的同级兄弟:

{
  "from": 0,
  "query": {
    "function_score": {
      "query": {
        ...
      },
      "script_score": {}       <--- script_score goes here
    }
  },
  "size": 10
}