# Visualize \> Metric aggregation on terms

**URL:** <https://discuss.elastic.co/t/visualize-metric-aggregation-on-terms/84023>\
**Category:** Kibana\
**Created:** [April 28, 2017, 2:39pm UTC](https://discuss.elastic.co/t/visualize-metric-aggregation-on-terms/84023 "2017-04-28T14:39:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgaillard](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@dgaillard](https://discuss.elastic.co/u/dgaillard)\
**Post date:** [April 28, 2017, 2:39pm UTC](https://discuss.elastic.co/t/visualize-metric-aggregation-on-terms/84023/1 "2017-04-28T14:39:47Z")

</div>

Hi everyone,

I'm trying to use Kibana 5.X to render data from an ES 5.X that is populate using an open source project, Apache Unomi.  
I'm pretty new to ES and even more to Kibana so I could be miss understanding how to reach my goal, I have spent some time reading the documentation and the forum but could not find what I needed.

I have a query which may not be perfect (if anyone know a better way to do that, you are welcome) but does work and now I would like to display the result of this query using Visualize \> Metric (one big number...), but I tried to reproduce my query using Kibana UI and could not do it, again they might have a better way to display this information and therefore to do it.

Here is my query:  
GET context-\*/\_search/  
{  
"query": {  
"bool": {  
"must": [  
{  
"query\_string": {  
"query": "\_type: event AND eventType: view",  
"analyze\_wildcard": true  
}  
}  
]  
}  
},  
"size": 0,  
"aggs": {  
"pages\_view\_per\_session": {  
"terms": {  
"field": "sessionId.keyword",  
"order": {  
"\_count": "desc"  
},  
"size": 20000  
}  
},  
"avg\_pages\_view\_per\_session": {  
"avg\_bucket": {  
"buckets\_path": "pages\_view\_per\_session.\_count"  
}  
}  
}  
}

So I'm getting all docs of type event with a property eventType = view and then I'm aggregating those docs using their property sessionId.keyword, which basically give the number of pages view by session and then I'm using this aggregate to calculate the average pages view per session which is the number that I would like to display using Visualize \> Metric

Also I have a bonus question, I didn't spend a lot of time on this one to be honest, and found some information on google but most of them are pretty old.  
Is it possible to create a visualization or a dashboard that display its visualization based on a parameter in its URL?  
My final goal is to build a generic dashboard that will display information based on a page path for example, so I will just display the dashboard in an iframe and add the page path to the url of the dashboard.

Thanks in advance for the help 🙂

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [April 28, 2017, 9:08pm UTC](https://discuss.elastic.co/t/visualize-metric-aggregation-on-terms/84023/2 "2017-04-28T21:08:06Z")

</div>

Hi Damien,

This is a really cool idea, but unfortunately the metric visualization doesn't provide a way to do anything other than a metric aggregation. There's no way in the Metric Visualize builder to start with a bucket aggregation and then pipe the data into an avg\_bucket pipeline aggregation.

If you feel up for it, would you mind creating an enhancement request in our issues page? [https://github.com/elastic/kibana/issues](https://github.com/elastic/kibana/issues)

-Tim

---

<div class="post-metadata">

**Author:** ![dgaillard](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@dgaillard](https://discuss.elastic.co/u/dgaillard)\
**Post date:** [May 2, 2017, 8:54am UTC](https://discuss.elastic.co/t/visualize-metric-aggregation-on-terms/84023/3 "2017-05-02T08:54:15Z")

</div>

Hi @tsullivan ,

Thanks for your answer, I will create an enhancement request.

Any idea about my second question?

> [@dgaillard](#):
>
> Also I have a bonus question, I didn't spend a lot of time on this one to be honest, and found some information on google but most of them are pretty old.Is it possible to create a visualization or a dashboard that display its visualization based on a parameter in its URL?My final goal is to build a generic dashboard that will display information based on a page path for example, so I will just display the dashboard in an iframe and add the page path to the url of the dashboard.

Thanks again for your help 🙂

Damien

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [May 2, 2017, 10:55pm UTC](https://discuss.elastic.co/t/visualize-metric-aggregation-on-terms/84023/4 "2017-05-02T22:55:20Z")

</div>

> [@dgaillard](#):
>
> Also I have a bonus question, I didn't spend a lot of time on this one to be honest, and found some information on google but most of them are pretty old.Is it possible to create a visualization or a dashboard that display its visualization based on a parameter in its URL?My final goal is to build a generic dashboard that will display information based on a page path for example, so I will just display the dashboard in an iframe and add the page path to the url of the dashboard.

This isn't documented, but the Dashboard URLs are made up of variables and conditions that are encoded in RISON. If you can de-code and re-construct those variables, then you can replace the values how you want. If you want to show a different dashboard based on a "page path," then look closely at how the URL changes when you add or remove a filter for that page path.

Another way to possibly do what you want would be to programmatically create saved dashboards that you need by constructing saved objects to store in the .kibana index. If you want to be able to show different dashboards in an iframe, you could just switch the `_id` of the dashboard in the iframe url. You can specify your own `_id` at index time, which would help a lot there.

If you don't have very many dashboards that you have to manage, you could also create a Markdown visualization that has links to the different dashboards. The Markdown viz would act as a control widget to navigate to different dashboards. Just add that visualization to each dashboard.

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [May 3, 2017, 3:39pm UTC](https://discuss.elastic.co/t/visualize-metric-aggregation-on-terms/84023/5 "2017-05-03T15:39:47Z")

</div>

Hi again Damien,

> [@dgaillard](#):
>
> ... I'm aggregating those docs using their property sessionId.keyword, which basically give the number of pages view by session and then I'm using this aggregate to calculate the average pages view per session which is the number that I would like to display using Visualize \> Metric

This actually will be possible in 5.4.0. There are new pipeline aggregation options available for most of the visualization types. For Metric aggregation, you'll be able to select "Average Bucket" as the aggregation type, and then choose a terms aggregation and a metric aggregation. I've played with this a little bit in a preview build and it looks like it can do exactly what you want.

> I'm getting all docs of type event with a property eventType = view

For this part, you would want to make a saved search for these docs, and then base the visualization off of that saved search.

A high-level intro to the pipeline features is given by @ppisljar in the video: [https://www.elastic.co/elasticon/conf/2017/sf/kibana-visualizations-deep-dive](https://www.elastic.co/elasticon/conf/2017/sf/kibana-visualizations-deep-dive) , so you can check that out too.

I hope you will be able to try out 5.4.0 when it comes out (soon)!

-Tim

---

<div class="post-metadata">

**Author:** ![dgaillard](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@dgaillard](https://discuss.elastic.co/u/dgaillard)\
**Post date:** [May 4, 2017, 1:24pm UTC](https://discuss.elastic.co/t/visualize-metric-aggregation-on-terms/84023/6 "2017-05-04T13:24:22Z")

</div>

Hi Tim,

Sorry for the late answer and thanks for all those information.  
I will check out everything, but so far it looks promising 🙂

Damien

---

<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:** [June 1, 2017, 1:30pm UTC](https://discuss.elastic.co/t/visualize-metric-aggregation-on-terms/84023/7 "2017-06-01T13:30:00Z")

</div>

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