# 2-phase aggregation on Y-axis value?

**URL:** <https://discuss.elastic.co/t/2-phase-aggregation-on-y-axis-value/31442>\
**Category:** Kibana\
**Created:** [October 1, 2015, 7:16am UTC](https://discuss.elastic.co/t/2-phase-aggregation-on-y-axis-value/31442 "2015-10-01T07:16:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ogibayashi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ogibayashi/32/32299_2.png) [@ogibayashi](https://discuss.elastic.co/u/ogibayashi)\
**Post date:** [October 1, 2015, 7:16am UTC](https://discuss.elastic.co/t/2-phase-aggregation-on-y-axis-value/31442/1 "2015-10-01T07:16:56Z")

</div>

Hi,

I have a requirement below and want some advise how to do this.

- Target log is kind of summarized access log which has fields like timestamp, click\_count, url, some\_parameter. Interval of timestamp is usually 10 seconds.  
For example:  
00:00:10, 10 , /a, p1  
00:00:11, 5 , /a, p2  
00:00:20, 3 , /a, p1  
00:00:21, 6 , /a, p2  
...  
00:01:10, 4, /a, p1  
00:01:10, 8, /a, p2  
...

- I want to visualize (on Kibana) sum of total click count per minute, but if we have multiple record for the same "url" and "some\_parameter" in the same minute, that value should be average.

In SQL, the aggregation can be like this:

```
SELECT -- The values to be plotted are sum(click_count) by URL
  timestamp, sum(click_count), url
FROM (
  SELECT -- calculate average 1 minute click_count by 'url' and 'some_parameter'
     round(timestamp,'min') as timestamp , avg(click_count), url, some_parameter
  FROM
     summary_access_log
  GROUP BY
     round(timestamp,'min'), url, some_parameter
)
GROUP BY
    url, timestamp

```

As far as I know, I can specify only one aggregation type for Y-axis, but what I want to do is kind of 2-phase aggregation, first do 'average' aggregation in one minute by url and some\_parameter, and then do 'sum' aggregation by url.

Are there any way to do this on Kibana?

Regards,  
Hironori Ogibayashi

---

<div class="post-metadata">

**Author:** ![tbragin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbragin/32/45166_2.png) [@tbragin](https://discuss.elastic.co/u/tbragin)\
**Post date:** [October 6, 2015, 7:39pm UTC](https://discuss.elastic.co/t/2-phase-aggregation-on-y-axis-value/31442/2 "2015-10-06T19:39:53Z")

</div>

A mockup of the type of visualization you're trying to accomplish based on the dataset above would help.

---

<div class="post-metadata">

**Author:** ![ogibayashi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ogibayashi/32/32299_2.png) [@ogibayashi](https://discuss.elastic.co/u/ogibayashi)\
**Post date:** [October 13, 2015, 10:12am UTC](https://discuss.elastic.co/t/2-phase-aggregation-on-y-axis-value/31442/3 "2015-10-13T10:12:28Z")

</div>

Here is a visualization of my data.

 ![](https://us1.discourse-cdn.com/elastic/original/2X/7/7dc671b459c1de837ec68b16cd8db74f3b006a2a.png)

I plotted 1 min. average click\_count, split lines by uri and split chart by param. The raw log data is generated every 10 seconds.  
What I really want is plotting the total value of click\_count by url (click\_count for param p1 + p2) , looks like this.

 ![](https://us1.discourse-cdn.com/elastic/original/2X/9/99750d9d5b5772fb307fc00cd638f88127441d27.png)

The problem is that: if I specify "Average" to the aggregation of Y-axis, the value will be the average of all the value in that 1 minute regardless of "param". I want values calculated by first taking average for values in 1 minute by each url and param , then sum up the values by url.

Does this make sense?

---

<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:** [July 6, 2017, 2:11pm UTC](https://discuss.elastic.co/t/2-phase-aggregation-on-y-axis-value/31442/4 "2017-07-06T14:11:30Z")

</div>

Closed on July 6, 2017, 2:11pm UTC


