如何对键上的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