Aggregation over collapsed field inner_hits?

Listing:
  item_id
  seller_id
  price

I want to group together all listings for the same item, and show the average price across all sellers.

I'm using field collapsing on item_id, but is there a way to to compute the average price of all items collapsed together?

  "collapse": {
    "field": "item_id",
    "inner_hits": {
      "name": "hits",                  
      "size": 200
    }  
  },

I started off bucketing by item_id and applying aggregations, but the cardinality of top_hits is sometimes large and queries are very slow, so I'm looking for optimizations and wondering if field collapsing could offer the same functionality.

I'm not sure but according to the NOTE here, collapsing does not affect aggregations.

What is the slow query? Could you share some queries you tried?

If you need average on sample 200 documents per item_id, how about using sampler aggregation between aggregations?

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