Elasticsearch date range get yesterday

I am looking for a way to get data from "yesterday" instead:

"range" : { "price" : { "gt" : "2014-11-24", "lt" : "2014-11-26" } } 

I would like something like:

 "range" : { "price" : { "eq" : "2014-11-25" } } 

Can anyone think this is possible?

I am thinking of something like:

 "range" : { "price" : { "gt" : "now-2d", "lt" : "now" } } 

But I would like to receive data from 00:00 a.m. to 00:00 p.m.

+6
source share
3 answers

Try the following:

  "query": { "range": { "price": { "gt": "now-1d/d", "lt": "now/d" } } } 
+10
source

The answer from @ andrei-stefan is a way to do this, but I wanted to add a little extra example to other people touching on this question.

If you want to receive data from yesterday from 12:00 to 13:00, and not for the whole day, you can do this with a little more math:

  "query": { "range": { "price": { "gt": "now-1d/d+12h", "lt": "now-1d/d+13h" } } } 

https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#date-math

+2
source

Better add a time zone. For example, if you are in CST6CDT, then to get data from 00:00 to 23:59 use this code -

 "query": { "range": { "price": { "gt": "now/d-1d/d", "lt": "now/d-1d/d", "time_zone":"CST6CDT" } } } 
0
source

Source: https://habr.com/ru/post/1207746/


All Articles