Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elasticsearch date range get yesterday

I'm looking a way to get the data from "yesterday" instead of:

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

I would like something like:

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

Does anybody think it could be possible?

I'm thinking of something like:

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

But I would like to get data from 00:00 am to 00:00 pm

like image 801
Alexandre Mélard Avatar asked Nov 26 '14 15:11

Alexandre Mélard


1 Answers

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

If you wanted to get data from yesterday between 12:00pm and 1:00pm rather than the whole day, you could do that with a little more date 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

like image 141
Mnebuerquo Avatar answered Oct 23 '22 23:10

Mnebuerquo