# Group by kibana Query

**URL:** <https://discuss.elastic.co/t/group-by-kibana-query/306617>\
**Category:** Kibana\
**Created:** [June 8, 2022, 2:28am UTC](https://discuss.elastic.co/t/group-by-kibana-query/306617 "2022-06-08T02:28:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chamod\_maduranga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chamod_maduranga/32/106703_2.png) [@chamod\_maduranga](https://discuss.elastic.co/u/chamod_maduranga)\
**Post date:** [June 8, 2022, 2:28am UTC](https://discuss.elastic.co/t/group-by-kibana-query/306617/1 "2022-06-08T02:28:11Z")

</div>

I have fields ID, Type, Count and timestamp as follows:

```auto
{ "ID": "15211", "Type": "C", "count": "17", "timestamp": "Jun 3, 2022 @ 12:26:34.000",....},
{ "ID": "11243", "Type": "C", "count": "64", "timestamp": "Jun 1, 2022 @ 11:16:34.000",....},
{ "ID": "11245", "Type": "B", "count": "127", "timestamp": "Jun 4, 2022 @ 09:46:34.000",....},
{ "ID": "159392", "Type": "A", "count": "63", "timestamp": "Jun 5, 2022 @ 04:22:34.000",....},
{ "ID": "123434", "Type": "B", "count": "567", "timestamp": "Jun 1, 2022 @ 11:35:34.000",....},

```

I would like to **get the latest(based on timestamp) data for each "Type"**

```auto
{ "Type": "C", "Count": ["17"],"ID": "15211",,"timestamp": "Jun 3, 2022 @ 12:26:34.000"}
{ "Type": "B", "Count": ["127"],"ID": "11245",,"timestamp": "Jun 4, 2022 @ 09:46:34.000"}
{ "Type": "A", "Count": ["17"],"ID": "15211",,"timestamp": "Jun 3, 2022 @ 12:26:34.000"}

```

What is the best way to do something like this in OpenSearch, Kibana?

---

<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 8, 2022, 2:28am UTC](https://discuss.elastic.co/t/group-by-kibana-query/306617/2 "2022-06-08T02:28:11Z")

</div>

OpenSearch/OpenDistro are AWS run products and differ from the original Elasticsearch and Kibana products that Elastic builds and maintains. You may need to contact them directly for further assistance.

(This is an automated response from your friendly Elastic bot. Please report this post if you have any suggestions or concerns :elasticheart: )

OpenSearch/OpenDistro are AWS run products and differ from the original Elasticsearch and Kibana products that Elastic builds and maintains. You may need to contact them directly for further assistance.

(This is an automated response from your friendly Elastic bot. Please report this post if you have any suggestions or concerns :elasticheart: )

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [June 8, 2022, 9:08am UTC](https://discuss.elastic.co/t/group-by-kibana-query/306617/3 "2022-06-08T09:08:46Z")

</div>

Duplicated posts?

> [@Get most recent distinct rows as kibana table](https://discuss.elastic.co/t/get-most-recent-distinct-rows-as-kibana-table/306524/2):
>
> Hi, Here is an example. Use Terms aggregation with Max sub-aggregation on timestamp field for split rows Buckets. Use Tophit Aggregation sort by timestamp.

---

<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 6, 2022, 9:09am UTC](https://discuss.elastic.co/t/group-by-kibana-query/306617/4 "2022-07-06T09:09:40Z")

</div>

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