首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Elasticsearch提供了[function_score]格式错误的查询,应为[END_OBJECT],但找到了[FIELD_NAME]

Elasticsearch提供了[function_score]格式错误的查询,应为[END_OBJECT],但找到了[FIELD_NAME]
EN

Stack Overflow用户
提问于 2018-08-27 20:14:00
回答 1查看 2K关注 0票数 1

我有一个查询,如下所示以使用function_score,但它给出了一个错误,即查询格式不正确,应该是END_OBJECT,但找到了FIELD_NAME。我已经检查了文档,但找不到与此不正确或不一致的地方。我没有在这里的script_score中添加任何脚本,但即使当我尝试添加脚本时,它也出现了同样的问题。

代码语言:javascript
复制
{
  "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
}

错误如下:

代码语言:javascript
复制
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]')
EN

回答 1

Stack Overflow用户

发布于 2018-08-27 20:24:24

script_score部分不在正确的位置,它需要是内部query的同级

代码语言:javascript
复制
{
  "from": 0,
  "query": {
    "function_score": {
      "query": {
        ...
      },
      "script_score": {}       <--- script_score goes here
    }
  },
  "size": 10
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52039140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档