# Aggregating data when the bucket interval should be "static"

**URL:** <https://discuss.elastic.co/t/aggregating-data-when-the-bucket-interval-should-be-static/224733>\
**Category:** Kibana\
**Created:** [March 23, 2020, 8:39pm UTC](https://discuss.elastic.co/t/aggregating-data-when-the-bucket-interval-should-be-static/224733 "2020-03-23T20:39:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![akrzos](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@akrzos](https://discuss.elastic.co/u/akrzos)\
**Post date:** [March 23, 2020, 8:39pm UTC](https://discuss.elastic.co/t/aggregating-data-when-the-bucket-interval-should-be-static/224733/1 "2020-03-23T20:39:32Z")

</div>

We have some data which is consistently sampled every 5 minutes from several sources and when displaying the data split over the sources as a "raw" value from each metric we simply use a TSVB metric aggregated with the max with an interval of `>=5m` and this works nicely. However if I want to aggregate all the sources data then display over a large period of time the aggregated data point will grow larger after the number of "buckets" which is determined by the interval gets to a certain point and becomes say `every 10 minutes`. What is the best practice in order to display data such as this?

To give an example to help illustrate this view the screen shot showing identical metrics graphed. The 1st metric is using an index pattern override with set to `5m` as the 2nd metric is using the panel options metric set to `>=5m`.

 ![Selection_072](https://us1.discourse-cdn.com/elastic/original/3X/7/4/741fdf3903e391d1d339db72850739c5444de6b0.png)

If you grow the time window, the bucket set to `>=5m` continues to grow which is not desired. What is the best practice in order to visualize this kind of data or is a new structure to the data being stored required?

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [March 25, 2020, 10:20am UTC](https://discuss.elastic.co/t/aggregating-data-when-the-bucket-interval-should-be-static/224733/2 "2020-03-25T10:20:25Z")

</div>

It's a workaround, but this configuration should give you the right number:

 ![Screenshot 2020-03-25 at 11.14.29](https://us1.discourse-cdn.com/elastic/original/3X/6/6/6624bcd7ccc2cf829d148f9bb02e1f29a4545b0e.png)

First agg is just the one you are actually after, Sum of k8s\_quota.alloctable.pods.total in your case.  
Then you apply cumulative sum on this agg, which will just sum up the value bucket by bucket.  
Then you take the derivative of the cumulative sum, which reverts the cumulative sum and gives you the original agg again - with the difference that you are able to specify a "unit" now which normalizes the metric - in your case to `5m`. This should do nothing when the auto interval was already 5min and give you half of the value if the interval jumped to 10min, and so on.

Keep in mind though that this might give you non-integer values for your metric in some cases because it effectively rounds the metric (in your case the number of pods) for the auto interval (e.g. if you select a really large time range and auto interval becomes 1 day, then it will give you the average number of pods for that day)

---

<div class="post-metadata">

**Author:** ![akrzos](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@akrzos](https://discuss.elastic.co/u/akrzos)\
**Post date:** [March 25, 2020, 8:37pm UTC](https://discuss.elastic.co/t/aggregating-data-when-the-bucket-interval-should-be-static/224733/3 "2020-03-25T20:37:52Z")

</div>

Thanks @flash1293, the workaround does work however it looks a bit ugly. Should I be simply creating another document to represent the data at the aggregation level I expect then? Are there any references to how to layout data for Elastic that could help me with this too?

Thanks again!

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [March 25, 2020, 8:47pm UTC](https://discuss.elastic.co/t/aggregating-data-when-the-bucket-interval-should-be-static/224733/4 "2020-03-25T20:47:04Z")

</div>

I always see this as a trade off - if you bring data into the right shape before ingesting it into Elasticsearch, you are buying performance and ease of use (for your specific use case), but you are sacrificing flexibility in changing your mind and querying your data in a different way later.

The “right” way depends on what’s important in your current situation. Unfortunately I don’t know good resources that summarize various scenarios.

A middle ground in the spectrum ease of use \<-\> flexibility is probably a data frame transform: [https://www.elastic.co/guide/en/elasticsearch/reference/current/put-transform.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/put-transform.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 22, 2020, 8:47pm UTC](https://discuss.elastic.co/t/aggregating-data-when-the-bucket-interval-should-be-static/224733/5 "2020-04-22T20:47:10Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
