无法使用查询在弹性搜索中实现日期范围过滤器

时间:2017-05-10 06:24:11

标签: date curl elasticsearch filter range

当我使用curl执行以下查询时

curl -XGET 'http://localhost:9200/logstash*/_search' -d '{ "query" : { "filter" : [  "range" : { "timestamp" : {"gt" : "2017-02-01 00:00:00","lt" : "2017-05-01 00:00:00"}}]}}'

我收到以下错误

{"error":{"root_cause":[{"type":"parsing_exception","reason":"[filter] query malformed, no start_object after query name","line":1,"col":26}],"type":"parsing_exception","reason":"[filter] query malformed, no start_object after query name","line":1,"col":26},"status":400}

但是如果我使用感知插件上面的查询执行日期范围过滤器,它运行正常。

弹性版本5.2

此致 KUNAL

1 个答案:

答案 0 :(得分:1)

您只需将查询更改为:

curl -XGET 'http://localhost:9200/logstash*/_search' -d '{
  "query": {
    "bool": {
      "filter": {
        "range": {
          "timestamp": {
            "gt": "2017-02-01 00:00:00",
            "lt": "2017-05-01 00:00:00"
          }
        }
      }
    }
  }
}'