# Aggregation by results of previous aggregation (not sub aggregation)

**URL:** <https://discuss.elastic.co/t/aggregation-by-results-of-previous-aggregation-not-sub-aggregation/42042>\
**Category:** Elasticsearch\
**Created:** [February 17, 2016, 3:57pm UTC](https://discuss.elastic.co/t/aggregation-by-results-of-previous-aggregation-not-sub-aggregation/42042 "2016-02-17T15:57:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Volodymyr\_Martynyak](https://avatars.discourse-cdn.com/v4/letter/v/b19c9b/32.png) [@Volodymyr\_Martynyak](https://discuss.elastic.co/u/Volodymyr_Martynyak)\
**Post date:** [February 17, 2016, 3:57pm UTC](https://discuss.elastic.co/t/aggregation-by-results-of-previous-aggregation-not-sub-aggregation/42042/1 "2016-02-17T15:57:26Z")

</div>

Hi!  
Maybe someone can help me with this:

I can store some geodata like :  
`"location": { "type": "geo_point", "geohash": true, "geohash_prefix": true }, "profile_id": { "type": "long" }, "updated_at": { "type": "date", "format": "dateOptionalTime" },`

I need to get 1 document per each "profile\_id" with maximum "updated\_at" which in some date range, and then group by "geohash\_grid" .

Can I do that with elasticsearch?

---

<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, 11:15pm UTC](https://discuss.elastic.co/t/aggregation-by-results-of-previous-aggregation-not-sub-aggregation/42042/2 "2017-07-05T23:15:41Z")

</div>


