# Kibana aggregations help

**URL:** https://discuss.elastic.co/t/kibana-aggregations-help/254582
**Category:** Kibana
**Created:** [November 6, 2020, 9:23pm UTC](https://discuss.elastic.co/t/kibana-aggregations-help/254582 "2020-11-06T21:23:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![smruthip](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@smruthip](https://discuss.elastic.co/u/smruthip)
#### Post date: [November 6, 2020, 9:23pm UTC](https://discuss.elastic.co/t/kibana-aggregations-help/254582/1 "2020-11-06T21:23:41Z")

</div>

Hi all,

I am trying to get the latest document based on a field

example  
'''  
container\_id state time  
1 A 2pm  
1 B 1pm  
1 C 6pm  
2 A 3pm  
2 B 6pm  
2 C 2pm

solution I want to display in Kibana is

state count  
A 0  
B 1 (current container state for container id 2)  
C 1 (current container state for container id 2)  
'''  
How do I do this in Kibana?

---

<div class="post-metadata">

### Author: ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)
#### Post date: [November 6, 2020, 11:02pm UTC](https://discuss.elastic.co/t/kibana-aggregations-help/254582/2 "2020-11-06T23:02:31Z")

</div>

You can get the latest document by using "top hits" metric. In the example below I am using a top hits metric aggregation to show the `timestamp` field for the last document sorted on the `timestamp` field.

 ![Screen Shot 2020-11-06 at 4.01.06 PM](https://us1.discourse-cdn.com/elastic/original/3X/1/4/146e63b2e12da1150a86018788fd3a8e1a58e1ad.png)

---

<div class="post-metadata">

### Author: ![smruthip](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@smruthip](https://discuss.elastic.co/u/smruthip)
#### Post date: [November 7, 2020, 12:41am UTC](https://discuss.elastic.co/t/kibana-aggregations-help/254582/3 "2020-11-07T00:41:00Z")

</div>

Hi Nathan ,

thank you. there needs to be another level of aggregation which is container\_id in my example above and show the count of each state.

 ![Screen Shot 2020-11-06 at 4.40.30 PM](https://us1.discourse-cdn.com/elastic/original/3X/f/2/f25e788a7acbe760c4f19d5a7e5cc502a55e2820.png)

What I actually need is

Staged 10  
Stacked 4  
Loaded 8

where 10 containers have a current state (based on latest timestamp) of Staged  
4 have Stacked  
8 have Loaded

---

<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 5, 2020, 12:41am UTC](https://discuss.elastic.co/t/kibana-aggregations-help/254582/4 "2020-12-05T00:41:03Z")

</div>

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