主要知识点:
在做下钻分析时的排序
需求,以颜色进行bucket,这里bucket里面的doc以其各品牌的平均价格排序,
GET /tvs/sales/_search
{
"size": 0,
"aggs": {"group_by_color": {
"terms": {"field": "color"},
"aggs": {"group_by_brand": {
"terms": {"field": "brand","order": {"avg_price": "desc"}},
"aggs": {"avg_price": {"avg": {"field": "price"}}}
}
}
}
}
}
这样红色里面有三星和长虹两个品牌,这两个品牌以平均价格排序。
"aggregations": {
"group_by_color": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "红色",
"doc_count": 4,
"group_by_brand": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "三星",
"doc_count": 1,
"avg_price": {
"value": 8000
}
},
{
"key": "长虹",
"doc_count": 3,
"avg_price": {
"value": 1666.6666666666667
}
}
]
}
},