Aggregation on top_hits aggregation results?


(Fidel Pamba) #1

Hi,

I've an offer data model containing a productId, a price and a rating.

I want to:

  1. Only retain the cheapest offer for each productId
  2. Compute the average rating for remaining offers

Here is what I've done below.

"aggs": {
  "reference_ids": {
    "terms": {
      "field": "catalogProductId",
      "size": 1000
    },
    "aggs": {
      "min_price": {
        "top_hits": {
          "sort": [
            {
              "price": {
                "order": "asc"
              }
            }
          ],
          "size": 1
        }
      }
    }
  }
}

Is it possible to make another aggregation (avg on rating) after the top_hits one?

Thanks,
Fidel


(system) #2

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