Date Hist Aggregation - Recreating "post_zone" (post ES 2.x)


Pre ES 2.x, I use the Date Histogram Aggregation and in particular the time zone related fields (pre_zone/post_zone), to aggregate data and return in the correct time zones.

I understand that in ES2.x, time_zone fully replaces pre_zone. However, the post_zone function has been completely dropped. This was rather valuable as I was able to give ES a timezone, and it would return the data bucketed in the correct time AND return the timestamp key for the BEGINNING of the interval. Now, it seems that there isn't a way to replicate post_zone without bringing all the date keys into the application and doing the date offset and rounding based on the interval.

Am I missing something? Is the post_zone function still producible in some manner? This almost seems like a regression in function to me...



the bucket keys in the aggregation are now always returned in UTC millis. If you want to display the value in the time zone that you use in the aggregation, this is returned in the key_as_string

  • the time_zone parameter shifts bucket boundaries to start/stop according to the specified time_zone
  • in the returned bucket: key_as_string returns a formated version of that key in the specified timezone, e.g. for "time_zone": "-02:00", a daily bucket would contain "key_as_string" : "2014-05-26T00:00:00.000-02:00", so this can be used to display local time instead of UTC. You can also specify different formats in the request, like e.g. with "format": "yyyy-MM-dd/" your would get "2014-05-26/00:00.00"

Hope this solves your problem.