# Could you please comment if the new aggregation module will solve my use case?

**URL:** <https://discuss.elastic.co/t/could-you-please-comment-if-the-new-aggregation-module-will-solve-my-use-case/13041>\
**Category:** Elasticsearch\
**Created:** [August 2, 2013, 12:16pm UTC](https://discuss.elastic.co/t/could-you-please-comment-if-the-new-aggregation-module-will-solve-my-use-case/13041 "2013-08-02T12:16:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertmattler](https://avatars.discourse-cdn.com/v4/letter/r/f4b2a3/32.png) [@robertmattler](https://discuss.elastic.co/u/robertmattler)\
**Post date:** [August 2, 2013, 12:16pm UTC](https://discuss.elastic.co/t/could-you-please-comment-if-the-new-aggregation-module-will-solve-my-use-case/13041/1 "2013-08-02T12:16:18Z")

</div>

Could you please comment if the new aggregation module will solve my use  
case?

If I have documents with these values.

\_source: {date: 01.01.2013 desc: XXX value: 100}  
\_source: {date: 02.01.2012 desc: XXX value: 200}  
\_source: {date: 03.01.2011 desc: XXX value: 300}  
\_source: {date: 04.01.2011 desc: YYY value: 400}  
\_source: {date: 05.01.2011 desc: YYY value: 500}

I need to produce:

Desc Last Date Last Value  
XXX 01.01.2013 100  
YYY 05.01.2011 500

I need to get the documents with the most recent date for that desc so I  
can pull the value off of it.  
If aggregation can not give me the document would it be possible to give  
the document id with the most recent date for that desc? And I could use an  
id filter to get the documents.

Thanks for your time.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)\
**Post date:** [August 2, 2013, 3:23pm UTC](https://discuss.elastic.co/t/could-you-please-comment-if-the-new-aggregation-module-will-solve-my-use-case/13041/2 "2013-08-02T15:23:15Z")

</div>

It won't do this for you exactly but you can probably get close. An  
aggregator like:

terms agg on desc:  
stats agg on date:

This should give you min and max date for your top desc values. You could  
then use that information to craft a query to get your most recent doc  
back: and(desc:XXX, date:01.01.2013). There also might be other  
approaches you can do as well. Have you looked into structuring your data  
differently? Maybe overwrite/update existing docs with latest date and  
value information so you don't have all these duplicates? Maybe use  
parent/child or nested documents?

Thanks,  
Matt Weber

On Fri, Aug 2, 2013 at 5:16 AM, [robertmattler@gmail.com](mailto:robertmattler@gmail.com) wrote:

> Could you please comment if the new aggregation module will solve my use  
> case?
> 
> If I have documents with these values.
> 
> \_source: {date: 01.01.2013 desc: XXX value: 100}  
> \_source: {date: 02.01.2012 desc: XXX value: 200}  
> \_source: {date: 03.01.2011 desc: XXX value: 300}  
> \_source: {date: 04.01.2011 desc: YYY value: 400}  
> \_source: {date: 05.01.2011 desc: YYY value: 500}
> 
> I need to produce:
> 
> Desc Last Date Last Value  
> XXX 01.01.2013 100  
> YYY 05.01.2011 500
> 
> I need to get the documents with the most recent date for that desc so I  
> can pull the value off of it.  
> If aggregation can not give me the document would it be possible to give  
> the document id with the most recent date for that desc? And I could use an  
> id filter to get the documents.
> 
> Thanks for your time.
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:23am UTC](https://discuss.elastic.co/t/could-you-please-comment-if-the-new-aggregation-module-will-solve-my-use-case/13041/3 "2017-07-06T02:23:12Z")

</div>


