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 results set.
Those categories would include smartphones, phone cases and mobile phone accessories.
If I search "iphone 6" I get 1400 results because of the extra "6" returns matches to more products. The product category aggregation now returns the top 3 categories for all those results.
The top 3 product categories will now be everything from cables to computer monitors.
What I need to do is get the top 3 categories for the top 100 results.
What I've tried:
I've tried using the top_hits
aggregation within the top category aggregation but that only returns the top products in each category.
Something like this:
{
"aggs": {
"product_categories": {
"terms": {
"field": "product_category",
"size": 10,
}
}
"aggs": {
"top-categories": {
"top_hits": {
"size" : 3
}
}
}
}
}
I've also tried creating a top_hits
aggregation with a sub-aggregation within to get the top categories but that doesn't work either.
{
"aggs": {
"top-categories": {
"top_hits": {
"size" : 100
}
"aggs": {
"product_categories": {
"terms": {
"field": "product_category",
"size": 3,
}
}
}
}
}
}
Can anyone help me with this problem?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…