Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting elasticsearch聚合按关键帧排序_Sorting_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Aggregation_Bucket Sort - Fatal编程技术网 elasticsearch,aggregation,bucket-sort,Sorting,elasticsearch,Aggregation,Bucket Sort" /> elasticsearch,aggregation,bucket-sort,Sorting,elasticsearch,Aggregation,Bucket Sort" />

Sorting elasticsearch聚合按关键帧排序

Sorting elasticsearch聚合按关键帧排序,sorting,elasticsearch,aggregation,bucket-sort,Sorting,elasticsearch,Aggregation,Bucket Sort,如何对关键字上的elasticsearch聚合进行排序。我有嵌套聚合,希望在第二个聚合结果上排序 像我一样: "result": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": 20309, "doc_count": 752,

如何对关键字上的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
                     },
                     ...
                  ]
               }
            },
我希望我的
事件
聚合存储桶在
impression
键或
页面视图
上按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
          }
        }
      }
    }
  }
}
我试过使用_键,但它在桶内排序。我想通过查看所有桶来分类。好像我有一个钥匙
的印象
。我想用这个键对我的结果进行排序。不在桶里

我希望我的结果设置为,如果我想按降序对
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
                         },
                         ...
                      ]
                   }
                },
i、 e具有最大压痕的铲斗应位于顶部。(按印象按降序排列桶)

尝试此聚合:

{
  "size": 0,
  "aggs": {
    "result": {
      "terms": {
        "field": "entity_id",
        "size": 10,
        "order": {
          "impression_Events": "desc"
        }
      },
      "aggs": {
        "Events": {
          "terms": {
            "field": "event_type",
            "min_doc_count": 0,
            "size": 10
          }
        },
        "impression_Events": {
          "filter": {
            "term": {
              "event_type": "impression"
            }
          }
        }
      }
    }
  }
}

请共享您正在运行的查询。通过使用
“order”:{“\u key”:“asc”}
或者我缺少什么?使用
\u key
将在bucket内排序。我想用所有的桶来分类。好像我有一个钥匙
的印象
。我想用这个键对我的结果进行排序。不是在Bucket中,你可以更改聚合的输出并显示所需的结果吗?@Andrei Stefan我已经更新了我的问题我尝试了这个,但它没有按照我的需要工作。我注意到你来自@elastic,如果我没有错的话。那么,我有什么办法可以获得这样的结果集呢?你能解释一下什么不是你所期望的吗?我已经更新了我的问题,并展示了我想要的结果。我在问为什么我的查询不适合你。请详细说明这个!