# ElasticSearch Max of Max?

**URL:** <https://discuss.elastic.co/t/elasticsearch-max-of-max/73485>\
**Category:** Elasticsearch\
**Created:** [February 1, 2017, 9:04am UTC](https://discuss.elastic.co/t/elasticsearch-max-of-max/73485 "2017-02-01T09:04:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![varundbest](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/varundbest/32/48066_2.png) [@varundbest](https://discuss.elastic.co/u/varundbest)\
**Post date:** [February 1, 2017, 9:04am UTC](https://discuss.elastic.co/t/elasticsearch-max-of-max/73485/1 "2017-02-01T09:04:24Z")

</div>

I need to search for max time (Recent entries), out of those max entries I want one with max value. I've tried various types of nesting on aggregation, using filters,etc. but it doesn't seem to work out. Any help?

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [February 2, 2017, 2:29am UTC](https://discuss.elastic.co/t/elasticsearch-max-of-max/73485/2 "2017-02-02T02:29:03Z")

</div>

Elasticsearch doesn't have a native "give me the value of X on the document with the maximum value of Y" aggregation. You have to hack it together with `scripted_metric`.

---

<div class="post-metadata">

**Author:** ![varundbest](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/varundbest/32/48066_2.png) [@varundbest](https://discuss.elastic.co/u/varundbest)\
**Post date:** [February 2, 2017, 12:27pm UTC](https://discuss.elastic.co/t/elasticsearch-max-of-max/73485/3 "2017-02-02T12:27:08Z")

</div>

What about returning all the field or specific fields corresponding to the doc with Max Value of time?

---

<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:** [March 2, 2017, 12:27pm UTC](https://discuss.elastic.co/t/elasticsearch-max-of-max/73485/4 "2017-03-02T12:27:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
