Currently I am developing a kibana advanced watcher and I need to get an average value of items from the previous day. I used the time range query in watcher but the watcher only executes in UTC time. I use now-1d/d and now/d for the query. I need to execute this query in the server timezone. As the document here the timezone cannot be applied to now option. Is there any alternative way to add the timezone different to the range query?
Watcher does not do anything special with how it executes the range query or date math. You
'now' will always be represented in UTC for date comparisons. The date it compares against is the field defined in the range field. https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html and if your dates are not already stored in UTC, you can use the timezone to normalize them to UTC for correct date comparison.
As long as everything is based in UTC (now, and the date field used for the range), the comparisons should be correct, and you should be able to change the offset for range itself. For example if you want 24 range hours in GMT+2
"gte": "now-22h/d", "lte": "now+2h/d"
I have not tested this, (and have a history of being wrong about time zones) so please test this. You should be able to use a normal range query to test then apply that to Watcher.
Thank you for the reply. I thought in the same way and will test it.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.