Here is my query. I have range and then aggregation. Both queries have timezone and start and end date on them.
So if you look at the first bucket on weekly aggregation for key 4138 it started from 1529798400000 but min value on extended bound is 1530403200000.
{ "query": { "bool": { "must": [{ "query_string": { "query": "data.owner_id:82" } }, { "range": { "@timestamp": { "gt": "2018-07-01T00:00:00", "lte": "2018-07-09T23:59:59", "format": "yyyy-MM-dd'T'HH:mm:ss", "time_zone": "+00:00" } } }] } }, "size": 0, "aggs": { "resultSet": { "terms": { "field": "data.asset_id", "size": 10000, "order": { "_count": "desc" } }, "aggs": { "weekly": { "date_histogram": { "offset": "-1d", "field": "@timestamp", "interval": "week", "min_doc_count": 0, "time_zone": "+00:00", "extended_bounds": { "min": 1530403200000, "max": 1531180799000 }, "order": { "_key": "asc" } }, "aggs": { "types": { "terms": { "field": "_type", "order": { "_count": "desc" } }, "aggs": { "progress": { "terms": { "field": "data.growth", "order": { "_count": "desc" } }, "aggs": { "count": { "sum": { "field": "data.count" } } } } } } } } } } } }
{ "aggregations": { "resultSet": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": 4138, "doc_count": 2537, "weekly": { "buckets": [ { "key_as_string": "2018-06-24T00:00:00.000Z", "key": 1529798400000, "doc_count": 0, "types": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [] } }, { "key_as_string": "2018-07-01T00:00:00.000Z", "key": 1530403200000, "doc_count": 2482, "types": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [] } }, { "key_as_string": "2018-07-08T00:00:00.000Z", "key": 1531008000000, "doc_count": 55, "types": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "1", "doc_count": 13, "progress": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [] } }, { "key": "3", "doc_count": 11, "progress": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ ] } }, { "key": "7", "doc_count": 10, "progress": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [] } }, { "key": "8", "doc_count": 6, "progress": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [] } }, { "key": "11", "doc_count": 5, "progress": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [] } }, { "key": "9", "doc_count": 5, "progress": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [] } }, { "key": "10", "doc_count": 3, "progress": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [] } }, { "key": "5", "doc_count": 2, "progress": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [] } } ] } } ] } } ] } } }