使用带有 bool 的范围时 Elasticsearch 查询抛出错误

Elasticsearch query throwing an error when using range with bool

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

"type": "parsing_exception","reason": "[status] query malformed, no start_object after query name"

查询如下所示:

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

错误是您没有针对状态字段指定查询类型(字词或匹配)。因此,如果状态是文本数据类型,则应执行匹配查询:

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

}