# Aggregation on latest updated documents

**URL:** <https://discuss.elastic.co/t/aggregation-on-latest-updated-documents/53956>\
**Category:** Elasticsearch\
**Created:** [June 26, 2016, 6:08am UTC](https://discuss.elastic.co/t/aggregation-on-latest-updated-documents/53956 "2016-06-26T06:08:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chaitanya118](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@chaitanya118](https://discuss.elastic.co/u/chaitanya118)\
**Post date:** [June 26, 2016, 6:08am UTC](https://discuss.elastic.co/t/aggregation-on-latest-updated-documents/53956/1 "2016-06-26T06:08:15Z")

</div>

I have a document which can be modified any number of times a day. I've ordered these document in time series creating index for each day. And each day would have multiple versions of the same document with different modified date.

Document sample:

{  
id: 1234,  
user: kc,  
subscriptions: [  
'paper1',  
'paper2'  
],  
modified\_date: 1466697434020  
}  
What I'm looking for is to get the latest documents in a particular time range for all users and to apply aggregation on top of it.

That would give a result like, in the last week/month how many people are subscribed for each of the papers.

Using top\_hits I was able to get the latest document for different users in a time range, but I cannot apply further aggregations on this set of data.

Suggestions are welcomed, for changing the data model to achieve this.

---

<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 5, 2017, 10:40pm UTC](https://discuss.elastic.co/t/aggregation-on-latest-updated-documents/53956/2 "2017-07-05T22:40:27Z")

</div>


