Using ElasticSearch, how to get data between a certain range of hours using range

0

Hello, I'm using ElasticSearch, and my query is not looking for the information I want.

{
    "query": 
    {
        "bool": 
        {
            "must": 
            [
                {
                    "range": 
                    {
                       "date": 
                       {
                           "gte": "2016-04-29 00:00:01",
                           "lte": "now"
                       }
                    }
                }
            ]
        }
    }
}

I've tried some variations, like putting:

"lte": "2016-04-29 23:59:59"

But it does not help, the result is all possible dates, basically it's as if this query did not even exist. Can anyone help me?

    
asked by anonymous 29.04.2016 / 15:13

1 answer

2

Perhaps the problem of not returning the filtered documents is related to the formatting of type datetime indexed.

I tested your query and the result was as expected, returned the documents filtered by date range, the only change was the inclusion of the format clause.

If format is not used the search parameters should have the same formatting as the properties present in the indexed documents.

{
    "query": 
    {
        "bool": 
        {
            "must": 
            [
                {
                    "range": 
                    {
                       "my_property_date": 
                       {
                            "format": "yyyy-MM-dd HH:mm:ss",
                            "gte": "2016-04-29 00:00:01",
                            "lte": "now"
                       }
                    }
                }
            ]
        }
    }
}

Click here to learn more about format | Elasticsearch

    
24.01.2017 / 21:10