Search code examples
jsonelasticsearchlogz.io

Filter date range "day before yesterday" in json query for logz.io api (elastic search)


Context: Querying logz.io through the API.

The following query returns results for yesterday

{ "size":10000, "query" : { "bool" : { "must" : [ { "range": { "@timestamp": { "gte": "now-1d/d", "lt": "now/d" } } } ] } } }

I was hoping this one to return results for the day before yesterday

{ "size":10000, "query" : { "bool" : { "must" : [ { "range": { "@timestamp": { "gte": "now-2d/d", "lt": "now-1/d" } } } ] } } }

But it doesn't return anything. What am I missing?


Solution

  • You're just missing a d in the lt part

    {
        "size":10000,
        "query" : {
            "bool" : {
                "must" : [
            { "range": { "@timestamp": { "gte": "now-2d/d", "lt": "now-1d/d" } } }
                                                                        ^
                                                                        |
                                                                      here
                         ]
            }
        }
    }