# Nested Filtered Aggregations

**URL:** <https://discuss.elastic.co/t/nested-filtered-aggregations/97939>\
**Category:** Elasticsearch\
**Created:** [August 22, 2017, 3:42pm UTC](https://discuss.elastic.co/t/nested-filtered-aggregations/97939 "2017-08-22T15:42:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_G](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@Ben\_G](https://discuss.elastic.co/u/Ben_G)\
**Post date:** [August 22, 2017, 3:42pm UTC](https://discuss.elastic.co/t/nested-filtered-aggregations/97939/1 "2017-08-22T15:42:20Z")

</div>

I'm looking for a way to get the min and max value from a 2 level nested object which have been filtered. So below im trying to get the min and max price which has a currencyCode GBP. Each product can have multiple skus and each sku can have multiple prices (though only 1 will be GBP):

```
"hits": [
  {
    "_index": "product",
    "_type": "main",
    "_id": "1",
    "_score": 1,
    "_source": {         
      "skus": [
        {
          "prices": [
            {
              "currencyCode": "GBP",
              "price": 15
            }
          ]
        }
      ]
    }
  },{
    "_index": "product",
    "_type": "main",
    "_id": "2",
    "_score": 1,
    "_source": {         
      "skus": [
        {
          "prices": [
            {
              "currencyCode": "GBP",
              "price": 20
            }
          ]
        }
      ]
    }
  },
{
    "_index": "product",
    "_type": "main",
    "_id": "3",
    "_score": 1,
    "_source": {         
      "skus": [
        {
          "prices": [
            {
              "currencyCode": "GBP",
              "price": 25
            }
          ]
        }
      ]
    }
  }]
 }

```

So I want min 15, max 25. I've looked into Filter Aggregation and Nested Aggregation but can not come up with the answer.

I'm using ElasticSearch version 5.5.

I'm trying to get the query working correctly first before converting to Nest .net.

Any help would be much appreciated.

---

<div class="post-metadata">

**Author:** ![Ben\_G](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@Ben\_G](https://discuss.elastic.co/u/Ben_G)\
**Post date:** [August 23, 2017, 7:51am UTC](https://discuss.elastic.co/t/nested-filtered-aggregations/97939/2 "2017-08-23T07:51:38Z")

</div>

Answered on stack overflow below

> <https://stackoverflow.com/questions/45821683/elasticsearch-nested-filtered-aggregations/45823885#45823885>

---

<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:** [September 20, 2017, 7:51am UTC](https://discuss.elastic.co/t/nested-filtered-aggregations/97939/3 "2017-09-20T07:51:47Z")

</div>

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