# Query to get latest comment of each user in the month

**URL:** <https://discuss.elastic.co/t/query-to-get-latest-comment-of-each-user-in-the-month/17494>\
**Category:** Elasticsearch\
**Created:** [May 13, 2014, 9:30pm UTC](https://discuss.elastic.co/t/query-to-get-latest-comment-of-each-user-in-the-month/17494 "2014-05-13T21:30:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aditya\_Raut](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@Aditya\_Raut](https://discuss.elastic.co/u/Aditya_Raut)\
**Post date:** [May 13, 2014, 9:30pm UTC](https://discuss.elastic.co/t/query-to-get-latest-comment-of-each-user-in-the-month/17494/1 "2014-05-13T21:30:53Z")

</div>

I have a es index which is of the following structure  
User: 1, timestamp: `13-5-2014`, comment: "abcded"  
User: 2, timestamp: `10-5-2014`, comment: "abcded"  
User: 1, timestamp: `12-5-2014`, comment: "abcded"  
User: 2, timestamp: `8-5-2014`, comment: "abcded"  
User: 3, timestamp: `5-5-2014`, comment: "abcded"  
User: 3, timestamp: `7-5-2014`, comment: "abcded"

I have been trying to think of a query using facets or aggregations to get  
the last comment of the month for each user.  
For example the result would be from the above the _bold_ only

_User: 1, timestamp: `13-5-2014`, comment: "abcded"_  
_User: 2, timestamp: `10-5-2014`, comment: "abcded"_  
_User: 3, timestamp: `7-5-2014`, comment: "abcded"_

Is there any way to do this?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/13605f9a-7506-401a-b918-6aaeadbf803e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/13605f9a-7506-401a-b918-6aaeadbf803e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![ElasticSearch\_Users\_](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@ElasticSearch\_Users\_](https://discuss.elastic.co/u/ElasticSearch_Users_)\
**Post date:** [May 13, 2014, 11:37pm UTC](https://discuss.elastic.co/t/query-to-get-latest-comment-of-each-user-in-the-month/17494/2 "2014-05-13T23:37:15Z")

</div>

Not at the moment. However you can do a terms agg on user, then nest a max  
agg on the timestamp. Then from the results that come back, you will need  
to run a second \_search to retrieve the comment values (using the user +  
timestamp combo for each bucket from the aggs).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/7b7de0cc-ee76-4759-bb46-2db34c4162f9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7b7de0cc-ee76-4759-bb46-2db34c4162f9%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 2017, 1:29am UTC](https://discuss.elastic.co/t/query-to-get-latest-comment-of-each-user-in-the-month/17494/3 "2017-07-06T01:29:38Z")

</div>

Closed on July 6, 2017, 1:29am UTC


