# Kibana data table with TopHit aggregation

**URL:** https://discuss.elastic.co/t/kibana-data-table-with-tophit-aggregation/212631
**Category:** Kibana
**Created:** [December 20, 2019, 9:04am UTC](https://discuss.elastic.co/t/kibana-data-table-with-tophit-aggregation/212631 "2019-12-20T09:04:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Manjula\_Piyumal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manjula_piyumal/32/57068_2.png) [@Manjula\_Piyumal](https://discuss.elastic.co/u/Manjula_Piyumal)
#### Post date: [December 20, 2019, 9:04am UTC](https://discuss.elastic.co/t/kibana-data-table-with-tophit-aggregation/212631/1 "2019-12-20T09:04:54Z")

</div>

Hi,

In my ELK setup I have documents like this,  
{  
"message\_id" : "1",  
"name" : "customer1",  
"login\_status": "loggedIn",  
"company": "Abc"  
},  
{  
"message\_id" : "2",  
"name" : "customer1",  
"login\_status": "loggedOut",  
"company": "Abc"  
},  
{  
"message\_id" : "3",  
"name" : "customer2",  
"login\_status": "logged\_in",  
"company": "Abc"  
},  
{  
"message\_id" : "4",  
"name" : "customer3",  
"login\_status": "loggin\_failed",  
"company": "XYZ"  
}

I want to visualize these information in a data table to show the current logged in status of each user. I have tried to do this using TopHit (top hit based on the message\_id filed - descending order) and I was able to visualize this as required. However, I want to put a input control to filter out based on the logging status. When I select the logged\_in status from the filter I'm getting the customer1 as a result due to the first record. I understand technically this is correct since as per my filtering criteria, first message is the latest record.  
However, I want to do the filtering only from the latest records for each customer. So when I filter for the logged\_in users, customer1 should be visible in the table.

Any idea on how to visualize this type of behavior? I have the feasibility to modify the json document structure if required. Really appreciate any help on this.

Thanks in advance.

Manjula

---

<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: [December 20, 2019, 1:47pm UTC](https://discuss.elastic.co/t/kibana-data-table-with-tophit-aggregation/212631/2 "2019-12-20T13:47:10Z")

</div>

i would suggest using Canvas and the ESSQL commands to try this, but I'll warn you that Elasticsearch isn't really for this, it's more for looking at historic data and trends.

---

<div class="post-metadata">

### Author: ![Manjula\_Piyumal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manjula_piyumal/32/57068_2.png) [@Manjula\_Piyumal](https://discuss.elastic.co/u/Manjula_Piyumal)
#### Post date: [December 26, 2019, 1:45am UTC](https://discuss.elastic.co/t/kibana-data-table-with-tophit-aggregation/212631/3 "2019-12-26T01:45:05Z")

</div>

Hi Marius,

Thank you for your reply, I’ll try with Canvas and yes, I understand your point about Elasticsearch. I’m using it for historical data and trends of course,but unfortunately I have this odd use case as well ☹  
Thanks

---

<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: [January 23, 2020, 1:45am UTC](https://discuss.elastic.co/t/kibana-data-table-with-tophit-aggregation/212631/4 "2020-01-23T01:45:06Z")

</div>

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