【问题标题】:Elasticsearch query throwing an error when using range with bool将范围与 bool 一起使用时 Elasticsearch 查询抛出错误
【发布时间】:2020-04-25 05:30:36
【问题描述】:

我正在使用 status fieldrange 查询弹性搜索,但出现错误:

"type": "parsing_exception","re​​ason": "[status] 查询格式错误,否 查询名称后的 start_object"

查询如下:

{
  "_source": {
    "includes": []
  },
  "query": {
    "bool": {
      "must": [
        {
            "status": "IN_PROGRESS"
        },
        {
          "range": {
            "requestDate": {
              "gte": "2018-10-01T08:00:00.000Z",
            }
          }
        }
      ]
    }
  },
  "sort": {
    "requestDate": {
      "order": "desc"
    }
  }
}

【问题讨论】:

    标签: json elasticsearch elastic-stack elasticsearch-5


    【解决方案1】:

    错误是您没有针对状态字段指定查询类型 - 术语或匹配。所以如果 status 是一个文本数据类型,你应该执行一个匹配查询:

    {
      "_source": {
        "includes": []
      },
      "query": {
        "bool": {
          "must": [
            {
              "match":{            "status": "IN_PROGRESS"
            }},
            {
              "range": {
                "requestDate": {
                  "gte": "2018-10-01T08:00:00.000Z",
                }
              }
            }
          ]
        }
      },
      "sort": {
        "requestDate": {
          "order": "desc"
        }
      }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      • 2020-07-19
      • 2022-01-03
      相关资源
      最近更新 更多