【发布时间】:2023-03-08 14:34:01
【问题描述】:
GET myIndex/_search
{
"from": 0,
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"user_id": {
"value": "a88604b0",
"boost": 1
}
}
},
{
"term": {
"entity_status.keyword": {
"value": "ACTIVE",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"sort": [
{
"txn_date": {
"order": "desc"
}
}
],
"aggs": {
"my_buckets": {
"composite": {
"sources": [
{
"group_by": {
"terms": {
"field": "category"
}
}
}
]
},
"aggs": {
"total_amount": {
"sum": {
"field": "amount"
}
}
}
}
}
}
我正在执行上述查询,但我希望聚合按子聚合排序
total_amount 按降序排列。是否有任何修改或其他方式来实现这一点?
这是上述查询的结果。
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 4,
"successful" : 4,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 22,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"my_buckets" : {
"after_key" : {
"group_by" : "Travel"
},
"buckets" : [
{
"key" : {
"group_by" : "Bills"
},
"doc_count" : 2,
"total_amount" : {
"value" : 86710.44
}
},
{
"key" : {
"group_by" : "Grocery"
},
"doc_count" : 1,
"total_amount" : {
"value" : 43355.22
}
},
{
"key" : {
"group_by" : "Fashion"
},
"doc_count" : 5,
"total_amount" : {
"value" : 216776.1
}
},
{
"key" : {
"group_by" : "Recharge"
},
"doc_count" : 7,
"total_amount" : {
"value" : 303486.54
}
},
{
"key" : {
"group_by" : "Shopping"
},
"doc_count" : 2,
"total_amount" : {
"value" : 86710.44
}
},
{
"key" : {
"group_by" : "Travel"
},
"doc_count" : 5,
"total_amount" : {
"value" : 216776.1
}
}
]
}
}
}
我希望聚合按照total_amount 进行排序。
【问题讨论】:
标签: java elasticsearch elastic-stack elasticsearch-aggregation aws-elasticsearch