ElasticSearch中的查询格式不正确

mutmk8jj  于 2022-12-03  发布在  ElasticSearch
关注(0)|答案(1)|浏览(196)
search = {
      "from": str(start),
      "size": str(size),
      "query": {
        "bool": {
          "must": {
            "multi_match": {
              "query":query,
              "fields":["name","description","tags","comments","created","creator","transaction","wallet"],
              "operator":"or"}
          },
          "filter": { "term": { "channel": channel } } } } }

这是python dict对象。它得到以下错误:

elasticsearch.BadRequestError: BadRequestError(400, 'parsing_exception', '[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]')

我没看到。请帮忙。开始、大小、查询和频道都是变量。
我看过很多ElasticSearch查询的例子。我尝试过的都没有语法错误。我也试过simple_search_string和一个简单的multi_match。我总是需要开始和大小,总是需要在通道上过滤。

tkqqtvp1

tkqqtvp11#

因此,问题是其中一些字段是数组,需要[]在其中。特别是must和filter。添加适当的大括号解决了这个问题。下面是新的格式:

search = {
  "from": start,
  "query": {
    "bool": {
      "must": [
        { "multi_match": {
          "query": query,
          "fields": ["name","description","tags","comments","created","creator","transaction","wallet"]
        } },
        { "match": {
          "channel": channel
        } }
      ]
    }
  }
}

请注意,我还放弃了使用过滤器,只添加了另一个匹配项。我在搜索调用中使用size作为其参数之一。

相关问题