0

Not able to filter the elasticsearch data based on dates. Not able to correctly figure out how to use "gt", "gte" in the URI to fetch Elasticsearch data.

localhost:9200/index/date:{"gte":2019-01-01 00:00:00}

Need to fetch all the docs that have date > 2019-01-01 00:00:00.

Anshuman
  • 39
  • 1
  • 5

2 Answers2

1

It's explained here. You can do it like this:

localhost:9200/index/_search?q=date:>=2019-01-01
localhost:9200/index/_search?q=date:[2019-01-01 TO *]
Val
  • 207,596
  • 13
  • 358
  • 360
  • Error : "type":"parse_exception","reason":"failed to parse date field [2018-01-01] with format [yyyy-MM-dd HH:mm:ss.S]"}] – Anshuman Aug 20 '19 at 09:43
  • I have already tried the updated version. Still facing the same error. – Anshuman Aug 20 '19 at 09:51
  • And try without the `T` between the date and the time, since your format seems to not have it – Val Aug 20 '19 at 11:58
  • I have tried it without the T also. The error in parsing still exists. – Anshuman Aug 20 '19 at 13:15
  • I've reproduced your case and updated my answer, both of the above queries work for a document having a `date` field with the following date `"2019-08-20 15:18:38.1"` – Val Aug 20 '19 at 13:24
0

The write method to query using elasticsearch was

localhost:9200/index/_search?q=date:["2018-01-01+00:00:00.0"+TO+"2019-09-02+00:00:00.0"]

as the format mentioned was [yyyy-MM-dd HH:mm:ss.S]

Anshuman
  • 39
  • 1
  • 5