Query - Get min/max of nested documents field for every root document

I have an index of products, with price on every date of year as a nested doc.

{ name: "nexus7",
prices: [
{date: "2014-09-01", price: 100},
{date: "2014-09-02", price: 200},
...
]}

I want to get the lowest price of each product. I tried nested aggregation

{
      "aggs": {
        "prices": {
          "aggs": {
            "min_price": {
              "min": {
                "field": "prices.price"
              }
            }
          }, 
          "nested": {
            "path": "prices"
          }
        }
      }
  }
}

But this return the minimum price among all products, which is not exactly what I need.
Is this possible to do?

Hi Sumit,

Had you reslove this problem? I am going through the same senairo. Please help

Thanks
Anushank

I think it can be solved by using a terms aggregation followed by a min sub aggregation.

Something like this should work.

{
      "aggs": {
        "products": {
          "terms": {
            "field": "name"
          },
          "aggs": {
            "prices": {
              "nested": {
                "path": "prices"
              },
              "aggs": {
                "min_price": {
                  "min": {
                    "field": "prices.price"
                  }
                }
              }
            }
          }
        }