Dynamic timezone offset in elasticsearch aggregation?

I collect documents, each of which has a time stamp. The timestamp is UTC, but each document also has a local time zone ( "timezone": "America/Los_Angeles" ), which may be different in different documents.

I'm trying to make date_histogram aggregation based on local time, not UTC or a fixed time zone (for example, using the "time_zone": "America/Los_Angeles" ).

How to convert the time zone for each document to its local time before aggregation?

Here's a simple aggregation:

 { "aggs": { "date": { "date_histogram": { "field": "created_timestamp", "interval": "day" } } } } 
+5
source share
2 answers

I'm not sure if I fully understand this, but it looks like the time_zone property will be for this:

The zone value accepts either the numerical value of the clock offset, for example: "time_zone": -2. It also accepts the format of hours and minutes, for example, "time_zone": "-02: 30". Another option is to provide a time zone that is accepted as one of the values ​​listed here.

0
source

If you save another field in which local time without time zone information, it should work.

Take each timestamp (which is in UTC), convert it to a date in the local time zone (this will contain information about the time zone). Now just drop the time zone information from that day and time. Now you can perform actions in this new field.

Suppose you start at this time in UTC: '2016-07-17T01: 33: 52.412Z'

Now, suppose you are in a PDT, you can convert it to: '2016-07-16T18: 33: 52.412-07: 00'

Now, crack the end so you are done: '2016-07-16T18: 33: 52.412Z'

Now you can work in this field.

0
source

Source: https://habr.com/ru/post/1201457/


All Articles