身安不如心安,屋宽不如心宽 。

对按日期聚合结果进行排序

Elasticsearch | 作者 broccoli_sup | 发布于2020年12月21日 | 阅读数:1389


abc.png

部分DSL如图片所示,按天设置聚合间隔统计天数,然后想根据sum_of_day进行排序,获取到前若干条,试了使用order直接报错了,望高手解惑,这种情况改该怎么排序
已邀请:

liuxg - Elastic

赞同来自:

直接在 aggs 里使用 order,比如:
 
GET twitter/_search
{
  "size": 0,
  "aggs": {
    "top_cities": {
      "terms": {
        "field": "city",
        "order": {
          "avg_age": "desc"
        }
      },
      "aggs": {
        "avg_age": {
          "avg": {
            "field": "age"
          }
        }
      }
    }
  }
}

要回复问题请先登录注册