Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Date Histogram Agg #3566

Closed
wants to merge 1 commit into from

Conversation

panda01
Copy link
Contributor

@panda01 panda01 commented Apr 9, 2015

Closes #3482.

[Agg/DateHistogram] Changed the date histogram Aggregation to use time_zone instead of pre_zone.

@spalger
Copy link
Contributor

spalger commented Apr 9, 2015

This works for intervals smaller than 1 day, but doesn't work for large intervals.

image

@spalger
Copy link
Contributor

spalger commented Apr 9, 2015

Reached out to @cbuescher for his opinion on the matter

@cbuescher
Copy link
Member

Tried this for week interval on current master. Not 100% sure what your expectations are here, but this is how it should work now:

  • time_zone shifts bucket boundaries to start/stop in the specified time_zone
  • in the returned bucket:
    • key is now always millis in UTC. I think this changed, using only "pre_zone" you were able to get buckets in local time, but this was one of the things we wanted to remove
    • key_as_string returns a formated version of that key in the specified timezone, e.g. for "time_zone": "-02:00"
"key_as_string": "2014-05-26T00:00:00.000-02:00",
  • you can specify a different format like e.g. format": "yyyy-MM-dd/HH:mm.ss#z would give you "2014-06-30/00:00.00#-02:00"

If you need the bucket date in local time, you should be able to either use the key_as_string or you have to do the math using the UTC key.

When I do this on some random dates on master I get:

GET /dates/docs/_search
{
  "query": { "match_all": {}}, 
    "aggs" : {
        "articles_over_time" : {
            "date_histogram" : {
                "field" : "date",
                "interval" : "week",
                "min_doc_count" : 0,
                "time_zone": "-02:00",
                "format": "yyyy-MM-dd/HH:mm.ss#z"
            }
        }
    }  
}

Returns:
"aggregations": {
      "articles_over_time": {
         "buckets": [
            {
               "key_as_string": "2014-05-26/00:00.00#-02:00",
               "key": 1401069600000,
               "doc_count": 1
            },
            {
               "key_as_string": "2014-06-02/00:00.00#-02:00",
               "key": 1401674400000,
               "doc_count": 0
            },
            {
               "key_as_string": "2014-06-09/00:00.00#-02:00",
               "key": 1402279200000,
               "doc_count": 0
            }
[...]
}

So the first bucket key is UTC 2014-05-26T02:00:00 but the key_as_string formats this in local time in the specified time zone.

Hope this helps, let me know if you need more info.

@panda01
Copy link
Contributor Author

panda01 commented Apr 10, 2015

That is incredibly helpful, Thanks!

@spalger
Copy link
Contributor

spalger commented Apr 15, 2015

Thanks for taking a look @cbuescher. Looks like it's just a disparity between 1.4.4 and master.

We won't be able to merge this until we bump the minimum elasticsearch version.

@rashidkpc
Copy link
Contributor

Closing in favor of #4301

@rashidkpc rashidkpc closed this Jun 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace pre/post_zone with time_zone in date_histogram
4 participants