【问题标题】:What is wrong with my Elastisearch query?我的 Elasticsearch 查询出了什么问题?
【发布时间】:2019-03-25 19:13:45
【问题描述】:

我需要同时进行 multi_match 和 bool 查询,但下面的查询不起作用:(当我单独使用它们时,它们工作得很好。

{
  "query": {
    "multi_match": {
      "query": "kotlety*",
      "fields": [
        "name"
      ]
    },
    "bool": {
      "filter": {
        "term": {
          "status": 2
        }
      }
    }
  },
  "size": 24
}

回复是:

{
    "error": {
        "root_cause": [
            {
                "type": "parsing_exception",
                "reason": "[multi_match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
                "line": 9,
                "col": 5
            }
        ],
        "type": "parsing_exception",
        "reason": "[multi_match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
        "line": 9,
        "col": 5
    },
    "status": 400
}

Elastic 6.6,我认为我的查询可能有错误的语法?

【问题讨论】:

    标签: elasticsearch elasticsearch-6


    【解决方案1】:

    查询不能同时包含 bool 和 multi_match。你可以像这样重新安排它:

    {
      "query": {
        "bool": {
          "filter": {
            "term": {
              "status": 2
            }
          },
          "should": {
            "multi_match": {
            "query": "kotlety*",
            "fields": [
              "name"
            ]
          }
        }
      }
      },
      "size": 24
    }
    

    【讨论】:

      【解决方案2】:

      我改变了语法并且这个查询有效:

      {
        "query": {
          "bool": {
            "must": {
              "multi_match": {
                "query": "kotlety*",
                "fields": [
                  "name"
                ]
              }
            },
            "filter": {
              "term": {
                "status": 2
              }
            }
          }
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2016-10-29
        • 2017-09-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-23
        • 1970-01-01
        • 1970-01-01
        • 2018-12-13
        相关资源
        最近更新 更多