【问题标题】:Elasticsearch gives [function_score] malformed query, expected [END_OBJECT] but found [FIELD_NAME]Elasticsearch 给出 [function_score] 格式错误的查询,预期为 [END_OBJECT] 但找到 [FIELD_NAME]
【发布时间】:2018-08-27 20:24:23
【问题描述】:

我有一个使用 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]')

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    script_score 部分不在正确的位置,它需要是内部query 的兄弟:

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

    【讨论】:

    • 这个运气好吗?
    猜你喜欢
    • 2022-10-25
    • 2017-12-01
    • 2018-01-30
    • 2018-02-10
    • 2018-04-25
    • 2021-04-22
    • 2020-02-26
    • 1970-01-01
    • 2022-01-14
    相关资源
    最近更新 更多