如何對鍵上的elasticsearch聚合存儲桶進行排序。我嵌套聚合,並想排序我的第二個聚合桶結果。elasticsearch聚合排序存儲桶密鑰
像我有:
"result": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 20309,
"doc_count": 752,
"Events": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "impression",
"doc_count": 30
},
{
"key": "page_view",
"doc_count": 10
},
...
]
}
},
{
"key": 20771,
"doc_count": 46,
"Events": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "impression",
"doc_count": 32
},
{
"key": "page_view",
"doc_count": 9
},
...
]
}
},
我想我Events
總水桶的遞減/遞增關鍵impression
或page_view
排序。 我該如何實現這樣的結果集?
這裏是我的查詢
GET someindex/useractivity/_search?search_type=count
{
"size": 1000000,
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"range": {
"created_on": {
"from": "2015-01-12",
"to": "2016-05-12"
}
}
},
{
"term": {
"group_id": 1
}
}
]
}
}
}
},
"aggs": {
"result": {
"terms": {
"field": "entity_id",
"size": 1000000
},
"aggs": {
"Events": {
"terms": {
"field": "event_type",
"min_doc_count": 0,
"size": 10
}
}
}
}
}
}
我一直在使用_key嘗試,但它那種鬥內。我想通過查看所有桶來進行排序。就像我有一把鑰匙impression
。我希望我的桶結果可以用這個鍵排序。不在鬥中。
我想我的結果設置爲一樣,如果我想降序排序上impression
那麼我的結果應該是
"buckets": [
{
"key": 20771,
"doc_count": 46,
"Events": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "impression",
"doc_count": 32
},
{
"key": "page_view",
"doc_count": 9
},
...
]
}
},
{
"key": 20309,
"doc_count": 752,
"Events": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "impression",
"doc_count": 30
},
{
"key": "page_view",
"doc_count": 10
},
...
]
}
},
即以最大的印象桶應該在最前面。 (爲了通過水桶印象降序排列)
請分享你正在運行的查詢。 – Richa
通過使用''命令':{ 「_key」:「asc」 }'或者我錯過了什麼? –
使用'_key'將在桶內排序。我想把它與所有水桶分類。就像我有一個關鍵的「印象」。我希望我的桶結果可以用這個鍵排序。不在桶內 – yakhtarali