Problem:
If I search for \"iphone\" I get 400 product results and the product category aggregation I have returns the top 3 categories in the result
You are looking for Sampler Aggregation. I have a similar answer at Aggregation on top n results
{
"aggs": {
"bestDocs": {
"sampler": {
"shard_size":100
},
"aggs": {
"product_categories": {
"terms": {
"field": "product_category",
"size": 3
}
}
}
}
}
It will take the top 100 docs sorted by their scores and then do term aggregation.