# How to group docs by latest doc and run aggregation on the group in elastic search?

**URL:** https://discuss.elastic.co/t/how-to-group-docs-by-latest-doc-and-run-aggregation-on-the-group-in-elastic-search/302524
**Category:** Elasticsearch
**Created:** [April 15, 2022, 8:53pm UTC](https://discuss.elastic.co/t/how-to-group-docs-by-latest-doc-and-run-aggregation-on-the-group-in-elastic-search/302524 "2022-04-15T20:53:30Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [April 16, 2022, 11:10am UTC](https://discuss.elastic.co/t/how-to-group-docs-by-latest-doc-and-run-aggregation-on-the-group-in-elastic-search/302524/3 "2022-04-16T11:10:25Z")

</div>

It’s a fairly common requirement to do analysis only on the last known state of an entity.  
See [here](https://discuss.elastic.co/t/get-last-document-string-value-in-each-bucket/260013/2) for solutions.

---

_[View the full topic](https://discuss.elastic.co/t/how-to-group-docs-by-latest-doc-and-run-aggregation-on-the-group-in-elastic-search/302524)._
