# Max Agg on lowest value inside a list property of the document

**URL:** <https://discuss.elastic.co/t/max-agg-on-lowest-value-inside-a-list-property-of-the-document/249875>\
**Category:** Elasticsearch\
**Created:** [September 24, 2020, 7:23pm UTC](https://discuss.elastic.co/t/max-agg-on-lowest-value-inside-a-list-property-of-the-document/249875 "2020-09-24T19:23:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thevu](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@thevu](https://discuss.elastic.co/u/thevu)\
**Post date:** [September 24, 2020, 7:23pm UTC](https://discuss.elastic.co/t/max-agg-on-lowest-value-inside-a-list-property-of-the-document/249875/1 "2020-09-24T19:23:04Z")

</div>

I'm looking to do a Max aggregation on a value of the property under my document, the property is a list of complex object (key and value). Here's my data:

```auto
[{
    "id" : "1",
    "listItems" : 
        [
            {
                "key" : "li1",
                "value" : 100
            },
            {
                "key" : "li2",
                "value" : 5000
            }
        ]
},
{
    "id" : "2",
    "listItems" : 
        [
            {
                "key" : "li3",
                "value" : 200
            },
            {
                "key" : "li2",
                "value" : 2000
            }
        ]
}]

```

When I do the Nested Max Aggregation on "listItems.value", I'm expecting the max value returned to be 200 (and not 5000), reason being I want the logic to first figure the MIN value under listItems for each document, then doing the Max Aggregation on that. Is it possible to do something like this?

Thanks.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 28, 2020, 9:07am UTC](https://discuss.elastic.co/t/max-agg-on-lowest-value-inside-a-list-property-of-the-document/249875/2 "2020-09-28T09:07:06Z")

</div>

Try using a `min` aggregation first, and then use the [max bucket aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/7.9/search-aggregations-pipeline-max-bucket-aggregation.html).

---

<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:** [October 26, 2020, 9:07am UTC](https://discuss.elastic.co/t/max-agg-on-lowest-value-inside-a-list-property-of-the-document/249875/3 "2020-10-26T09:07:14Z")

</div>

Closed on October 26, 2020, 9:07am UTC

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