# Aggregation bucket sum + max group by time with filtering

**URL:** https://discuss.elastic.co/t/aggregation-bucket-sum-max-group-by-time-with-filtering/264718
**Category:** Kibana
**Created:** [February 18, 2021, 2:38pm UTC](https://discuss.elastic.co/t/aggregation-bucket-sum-max-group-by-time-with-filtering/264718 "2021-02-18T14:38:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Tim4](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim4/32/84120_2.png) [@Tim4](https://discuss.elastic.co/u/Tim4)
#### Post date: [February 18, 2021, 2:38pm UTC](https://discuss.elastic.co/t/aggregation-bucket-sum-max-group-by-time-with-filtering/264718/1 "2021-02-18T14:38:13Z")

</div>

Hi, I'm in need of some help.

Let's start of with some sample data:

Datetime \_\_\_\_\_\_\_\_\_\_\_\_| User | Mbps  
18/02/2021 12:00:00 | a \_\_\_ | 10  
18/02/2021 12:00:00 | b \_\_\_ | 5  
18/02/2021 12:20:00 | a \_\_\_ | 10  
18/02/2021 12:45:00 | b \_\_\_ | 5  
18/02/2021 12:45:00 | a \_\_\_ | 5

So every doc is one datetime, user and Mbps  
What i want to do is group the data by datetime and get the sum of the Mbps and users.  
So far so simple. Now i want to group the datetime **per hour** and show the max Mbps and max users value.

* * *

Datetime \_\_\_\_\_\_\_\_\_\_\_\_| User | Mbps | MAX Mbps  
18/02/2021 12:00:00 | a \_\_\_ | 10 \_\_\_ |  
18/02/2021 12:00:00 | b \_\_\_ | 5 \_\_\_\_ | 15

* * *

18/02/2021 12:20:00 | a \_\_\_ | 10 \_\_\_ | 10

* * *

18/02/2021 12:45:00 | b \_\_\_ | 5 \_\_\_\_ |  
18/02/2021 12:45:00 | a \_\_\_ | 5 \_\_\_\_ | 10

* * *

Datetime \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_| User Max | Mbps Max  
18/02/2021 12:00:00 - 13:00:00| 2 (a+b) \_\_\_| 15 (10 + 5) - This would be one point in the line graph.

I want to show a line graph in kibana showing the result per hour.

So that's my use case.

How can this be done?  
And how can this be done with the ability to filter on user. let's say i want the result only for user a.?

---

<div class="post-metadata">

### Author: ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)
#### Post date: [February 18, 2021, 5:30pm UTC](https://discuss.elastic.co/t/aggregation-bucket-sum-max-group-by-time-with-filtering/264718/2 "2021-02-18T17:30:16Z")

</div>

These sorts of complicated use cases don't have a great solution using aggregations themselves, but really can be solved better using "entity-centric indexing". Here's a video that describes the concept:

> **[Entity-Centric Indexing - Mark Harwood](https://www.elastic.co/videos/entity-centric-indexing-mark-harwood)**

The idea here is that every hour we'd have a script that, every hour, looks at the last hour of documents, performs the calculations as you've described, then indexes a new document that looks like the output of your calculations.

---

<div class="post-metadata">

### Author: ![Tim4](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim4/32/84120_2.png) [@Tim4](https://discuss.elastic.co/u/Tim4)
#### Post date: [February 22, 2021, 8:14am UTC](https://discuss.elastic.co/t/aggregation-bucket-sum-max-group-by-time-with-filtering/264718/3 "2021-02-22T08:14:23Z")

</div>

Thanks for your reply. Is it possible to use Kibana to create a graph from an external URL.  
I can generate a sum of users and Mbps for the time ranges and know i can create the max in like say PHP. The Flow would be.

Elasticsearch → Query for sum per time range → PHP get max for every hour → out put JSON results → show JSON results in graph in Kibana.

Does anyone have experience in doing the last step "show JSON results in graph in Kibana" from an external source?

---

<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: [March 22, 2021, 8:14am UTC](https://discuss.elastic.co/t/aggregation-bucket-sum-max-group-by-time-with-filtering/264718/4 "2021-03-22T08:14:27Z")

</div>

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