kunalp
kunalp

Reputation: 11

Unable to implement date range filter in elastic search using query

when I am executing below query using 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"}}]}}'

I am getting below error

{"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}

But if I am executing the date range filter with above query from sense plugin, it is running fine.

Elastic version 5.2

Regards, Kunal

Upvotes: 0

Views: 917

Answers (1)

Val
Val

Reputation: 217314

You simply need to change your query to this:

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"
          }
        }
      }
    }
  }
}'

Upvotes: 1

Related Questions