Bucketed aggregation on nested fields

Good morning,
I need to compute a bucketed aggregation on nested fields where the buckets correspond to the nested objects.
Can you tell me if it’s possible at all and in case help me with the query?
For clarity I refer to this example from ES documentation

The docs are resellers (resellers are the nested entities) prices for products.

{
  "name": "LED TV", 
  "resellers": [
    {
      "reseller": "companyA",
      "price": 350
    },
    {
      "reseller": "companyB",
      "price": 500
    }
  ]
}

{
  "name": "Washing Machine", 
  "resellers": [
    {
      "reseller": "companyC",
      "price": 1350
    },
    {
      "reseller": "companyD",
      "price": 1500
    }
  ]
}

The query from ES documentation computes the minimum price for a specific product
Query

{
  "query": {
    "match": { "name": "led tv" }
  },
  "aggs": {
    "resellers": {
      "nested": {
        "path": "resellers"
      },
      "aggs": {
        "min_price": { "min": { "field": "resellers.price" } }
      }
    }
  }
}

Response

{
  ...
  "aggregations": {
       "min_price": {
           "value": 350.0
       }
}

What we are looking for is a query to compute the minimum price for each product
Query: ?

Expected Response:

{
  ...
  "aggregations": {
    "resellers": {
      "min_prices": [
       {“name”:“Led TV”, "value": 350},
       {“name”:“Washing Machine”, "value": 1350}
      ]
    }
  }
}

Thank you

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