Nested Filtered Aggregations


(Ben G) #1

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.


(Ben G) #2

Answered on stack overflow below


(system) #3

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