どのようにキーのelasticsearch集計バケットを並べ替えるのですか?私は集計をネストしていて、2番目の集計バケットの結果を並べ替える必要があります。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
にDESC/ASCでソートしたいです。 このような結果セットはどのように達成できますか?ここで
は私のクエリ
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