【问题标题】:getting query_string malformed query, expected [END_OBJECT] but found [FIELD_NAME]获取 query_string 格式错误的查询,应为 [END_OBJECT] 但找到 [FIELD_NAME]
【发布时间】:2020-08-30 13:43:24
【问题描述】:

当我尝试执行以下查询时,我收到异常 [query_string] 格式错误的查询,应为 [END_OBJECT] 但找到 [FIELD_NAME]

{
  "query" : {
   "query_string": {
        "default_field": "shipmentId",
        "query": "\"123\""
    },
    "bool" : {
      "filter" : {
        "terms" : {
          "exceptionId" : ["1", "2"]
        }
      },
      "must_not" : {
        "terms" : {
          "id" : ["1"]
        }
      }
    }
  }
}

【问题讨论】:

    标签: elasticsearch elasticsearch-aggregation elasticsearch-dsl


    【解决方案1】:

    您的查询几乎是正确的,您只需将query_string 查询移到bool/must 部分:

    {
      "query": {
        "bool": {
          "must": {
            "query_string": {
              "default_field": "shipmentId",
              "query": "\"123\""
            }
          },
          "filter": {
            "terms": {
              "exceptionId": [
                "1",
                "2"
              ]
            }
          },
          "must_not": {
            "terms": {
              "id": [
                "1"
              ]
            }
          }
        }
      }
    }
    

    【讨论】:

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