# Show in Kibana a Metric with the output of an arbitrary elasticsearch query

**URL:** <https://discuss.elastic.co/t/show-in-kibana-a-metric-with-the-output-of-an-arbitrary-elasticsearch-query/209442>\
**Category:** Kibana\
**Created:** [November 26, 2019, 7:59am UTC](https://discuss.elastic.co/t/show-in-kibana-a-metric-with-the-output-of-an-arbitrary-elasticsearch-query/209442 "2019-11-26T07:59:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![IvanHerreros](https://avatars.discourse-cdn.com/v4/letter/i/35a633/32.png) [@IvanHerreros](https://discuss.elastic.co/u/IvanHerreros)\
**Post date:** [November 26, 2019, 7:59am UTC](https://discuss.elastic.co/t/show-in-kibana-a-metric-with-the-output-of-an-arbitrary-elasticsearch-query/209442/1 "2019-11-26T07:59:36Z")

</div>

I want to display in Kibana a metric visualization (a.k.a. a number) whose value computed with a pipeline aggregation ES query.

More concretely the query is built based on this one: [https://stackoverflow.com/questions/46908360/sql-like-group-by-and-having/46953947#46953947](https://stackoverflow.com/questions/46908360/sql-like-group-by-and-having/46953947#46953947)

This is the output of the query (truncated):

```
 {...,
    "aggregations": {
        "reseller_sale_sum": {
           "doc_count_error_upper_bound": 0,
           "sum_other_doc_count": 0,
           "buckets": [
              ...
           ]
         },
         "max_sales_stats": {
         "value": 1
       }
    }
 }

```

And what I would like to display the value of `max_sales_stats` in a Kibana Metric visualization.

Is there a way of achieving this, even outside of the GUI (ie, directly editing a `saved object`)?

---

<div class="post-metadata">

**Author:** ![christophilus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christophilus/32/42991_2.png) [@christophilus](https://discuss.elastic.co/u/christophilus)\
**Post date:** [November 26, 2019, 4:53pm UTC](https://discuss.elastic.co/t/show-in-kibana-a-metric-with-the-output-of-an-arbitrary-elasticsearch-query/209442/2 "2019-11-26T16:53:15Z")

</div>

We don't really have a robust query building mechanism in our standard metric visualization.

It's not clear to me exactly what you're trying to build, but it sounds like something you can _probably_ use TSVB to build.

As a last resort, generally speaking, you can run almost any Elasticsearch query in Vega. Vega can be a bit tricky (you've got to understand Vega, Elasticsearch, and the way Kibana uses Vega).

---

<div class="post-metadata">

**Author:** ![IvanHerreros](https://avatars.discourse-cdn.com/v4/letter/i/35a633/32.png) [@IvanHerreros](https://discuss.elastic.co/u/IvanHerreros)\
**Post date:** [November 27, 2019, 12:48pm UTC](https://discuss.elastic.co/t/show-in-kibana-a-metric-with-the-output-of-an-arbitrary-elasticsearch-query/209442/3 "2019-11-27T12:48:29Z")

</div>

Hi Chris, thanks your answer.

I will describe you the concrete use case: We have applicants for jobs. Some applicants may apply for more than one job within our system, let's call them "recurring applicants" (as "recurring customers"). We would like to display not just the count of unique applicants (as we do using a Unique count), but also the unique count of recurring applicants. I have an ES query that yields this number, but there's no way for me to display it in Kibana (using a Metric visualization).

On the other hand, I imagine that Vega is flexible enough to produce it, but then I have understood that Kibana filters won't apply in the Vega plots.

I have looked at TSVB visualization but I was not obvious for me how to proceed with it. Would you have a more concrete suggestion.

---

<div class="post-metadata">

**Author:** ![IvanHerreros](https://avatars.discourse-cdn.com/v4/letter/i/35a633/32.png) [@IvanHerreros](https://discuss.elastic.co/u/IvanHerreros)\
**Post date:** [November 29, 2019, 2:38pm UTC](https://discuss.elastic.co/t/show-in-kibana-a-metric-with-the-output-of-an-arbitrary-elasticsearch-query/209442/4 "2019-11-29T14:38:30Z")

</div>

If my understanding is right, this is not yet possible, but because of entirely understandable reasons, there's a plan of allowing something similar in the future:

> **[Reusing saved queries in Kibana across Dashboard, Visualize, and Discover](https://www.elastic.co/blog/reusing-saved-queries-in-kibana-across-dashboard-visualize-and-discover)**
>
> Kibana 7.4 shows off a new feature called saved queries, which are portable queries that can be reused anywhere a search bar is present. Learn how to save time by easily saving and reusing queries across your dashboards, visualizations, and Discover.

Quoting from that blog:

> We also see saved queries as a building block for some other powerful features. Imagine being able to create filters in the filter bar based on saved queries, giving us an easy way to combine existing queries. In a similar vein, we could develop a syntax for referencing saved queries inside a [KQL expression](https://www.elastic.co/guide/en/kibana/7.4/kuery-query.html). That would allow for effortless reuse of saved queries in places where a query text input is available without the full search bar, like the filters aggregation in Visualize. Having a way to save a portable set of filters in Kibana will open up all kinds of possibilities.

---

<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:** [December 27, 2019, 2:38pm UTC](https://discuss.elastic.co/t/show-in-kibana-a-metric-with-the-output-of-an-arbitrary-elasticsearch-query/209442/5 "2019-12-27T14:38:35Z")

</div>

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