0

The current time say is "2017-10-01T06:27:17+0000"

So to query to data less than equal to time "2017-10-01T06:00:00+0000" I have date range query

"range": {
        "entryDate": {
                    "lte": "now/h"
        }
    }

Would it work? What would now/h evaluate to? I want to round off to hour.

So should I use "/h" or "/H" ?

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

user2368055
  • 410
  • 6
  • 14

1 Answers1

0

My understanding of /h vs /H is that /H is merely an alias of /h, they both should be equivalent.

As far as what now/h evaluates to, it will round down to the nearest hour. For example, the time as I write this, it is approximately 2017-10-02T01:02:48. Using the expression provided in your example, I would return all documents which have an "entryDate" <= 2017-10-02T01:00:00.

Your sample should correctly do the rounding you desire.

Miek
  • 1,190
  • 7
  • 18
  • will there be any difference using "/h" vs "/H". Using "lte" I did not get the desired result but when I used "lt", it gave me the desired result. So to me it appeared as if lte took into consideration all the data available in the current hour including the current minute. The undesired result shows the datemath (/h) converted it to 2017-10-02T02:00:00 – user2368055 Oct 03 '17 at 08:01
  • /h should equal /H, the documentation does not indicate any difference from my research into it. LT vs LTE will have different behavior, LTE being "less than or equal" and LT being "less than". According to the docs, if you want time down to the current minute, you would want to use "now/m". May I ask what version of Elastic you're using? – Miek Oct 03 '17 at 15:01
  • I want to exclude the min. I got the desired behaviour by using LT. Just for knowledge I am investigating. I needed to execute on data till the last hour. I am using ElasticSearch 5.1 – user2368055 Oct 03 '17 at 18:13