# Kibana - metric with top hits based on string

**URL:** <https://discuss.elastic.co/t/kibana-metric-with-top-hits-based-on-string/275738>\
**Category:** Kibana\
**Created:** [June 12, 2021, 9:11pm UTC](https://discuss.elastic.co/t/kibana-metric-with-top-hits-based-on-string/275738 "2021-06-12T21:11:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kelvins](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kelvins](https://discuss.elastic.co/u/kelvins)\
**Post date:** [June 12, 2021, 9:11pm UTC](https://discuss.elastic.co/t/kibana-metric-with-top-hits-based-on-string/275738/1 "2021-06-12T21:11:39Z")

</div>

Hello - I have been hunting around, and I think I cannot actually do what it is I want to do, but am wanting to confirm my suspicions.

The plan is to read the data from a log, to see the progress of users downloading files. There are a number of statuses that the clients can go through: RECEIVED, PROCESSED, ERROR or COMPLETE. What I would like, is a metric showing the count of clients in each state (really only COMPLETE or ERROR). To do this, I will need to use the _TOP HITS_ metric to get the _current_ state of a client and then count the records returned. However, as statuses are a keyword, I loose the ability to count.

Is there a way to actually do this?

Some sample data would be

```auto
{ "create": {} }
{"@timestamp": "2021-06-09T16:21:15.000Z","filename":"Accessory.json.gz","name" : "harold","status" : "RECEIVED"}
{ "create": {} }
{"@timestamp": "2021-06-09T16:21:16.000Z","filename":"Accessory.json.gz","name" : "harold","status" : "ERROR"}
{ "create": { } }
{ "@timestamp": "2021-06-09T17:21:15.000Z","filename":"Accessory.json.gz","name" : "bob","status" : "RECEIVED"}
{ "create": { } }
{ "@timestamp": "2021-06-09T17:21:15.000Z","filename":"Accessory.json.gz","name" : "bob","status" : "PROCESSED"}
{ "create": { } }
{ "@timestamp": "2021-06-09T17:21:16.000Z","filename":"Accessory.json.gz","name" : "bob","status" : "COMPLETE"}
{ "create": { } }
{ "@timestamp": "2021-06-09T18:21:15.000Z","filename":"Accessory.json.gz","name" : "richard","status" : "RECEIVED"}
{ "create": { } }
{ "@timestamp": "2021-06-09T18:21:16.000Z","filename":"Accessory.json.gz","name" : "richard","status" : "PROCESSED"}
{ "create": { } }
{ "@timestamp": "2021-06-09T18:21:17.000Z","filename":"Accessory.json.gz","name" : "richard","status" : "COMPLETE"}

```

I can show the the current client status in a datatable, but displaying in a metric is easy to read and understand at a glance.

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [June 17, 2021, 11:05am UTC](https://discuss.elastic.co/t/kibana-metric-with-top-hits-based-on-string/275738/2 "2021-06-17T11:05:59Z")

</div>

Can you try doing using that in a TSVB metric? Then you can use the math aggregation and count stuff as well.

---

<div class="post-metadata">

**Author:** ![ghudgins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ghudgins/32/138532_2.png) [@ghudgins](https://discuss.elastic.co/u/ghudgins)\
**Post date:** [June 17, 2021, 8:08pm UTC](https://discuss.elastic.co/t/kibana-metric-with-top-hits-based-on-string/275738/3 "2021-06-17T20:08:01Z")

</div>

Also should be able to do "Top Values" in Lens. If the field isn't available for aggregation you could adjust your index pattern so it's Aggregatable

---

<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 15, 2021, 8:08pm UTC](https://discuss.elastic.co/t/kibana-metric-with-top-hits-based-on-string/275738/4 "2021-07-15T20:08:23Z")

</div>

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