Double aggregate data (Nested Aggregation) and plot in a bar chart in Kibana

社会主义新天地 提交于 2019-12-11 23:38:37

问题


Is there a way to perform a nested aggregation from Kibana (v6.7.0)? I've been looking at aggregating with buckets and sub-buckets, but to no avail.

Say the data looks as follows (with ID being a string and Source also being a string:

| ID | Source |
===============
| a1 | srcA   |
| a1 | srcB   |
| a1 | srcC   |
| b2 | srcA   |
| b2 | srcB   |
| c3 | srcA   |
| d4 | srcA   |
| d4 | srcB   |

I'd like to visualize how many IDs are in N sources, i.e. a double aggregation. In SQL-Land, the first level of aggregation would be:

SELECT ID, COUNT(1) as N_SRC FROM DATA GROUP BY ID

yielding something like this:

| ID  | N_SRC |
===============
| a1  | 3     |
| b2  | 2     |
| c3  | 1     |
| d4  | 2     |

So, what I am after is the possibility to run a nested aggregation as such:

SELECT N_SRC, COUNT(1) AS N FROM (
    SELECT ID, COUNT(1) as N_SRC FROM DATA GROUP BY ID
    ) AS AGG_1 
GROUP BY N_SRC

which would aggregate to the following:

| N_SRC | N   |
===============
| 1     | 1   |
| 2     | 2   |
| 3     | 1   |

And a vertical bar chart would be looking something like this:

N
|       ___ 
|  ___  | |  ___
|__|_|__|_|__|_|___
    1    2    3    N_SRC   

It can also be a horizontal bar chart of course.

This question seems similar, but doesn't have a satisfactory answer: (Elasticsearch - Kibana - Group By and Count) Also, I'd be after a bar chart and not a pie chart!

I've also looked at this, this and this but the answers are either quite dated or not applicable.

来源:https://stackoverflow.com/questions/56020792/double-aggregate-data-nested-aggregation-and-plot-in-a-bar-chart-in-kibana

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!