使用 shuf 来打乱一个文件中的行或是选择文件中一个随机的行。

select a, b, sum(c) fromt table group by a, b order by sum(c); 这种sql 用es怎么实现

Elasticsearch | 作者 zhangli | 发布于2017年09月12日 | 阅读数:5485

系统提示:这个人太懒了,什么问题描述都没有写!

已邀请:

Cheetah

赞同来自: exceptions novia

如下,以a,b普通聚合,c sum,排序条件为c的值{
  "query" : {
    "match_all" : { }
  },
  "aggregations" : {
    "a" : {
      "terms" : {
        "field" : "a",
        "order" : {
          "c.value" : "asc"
        }
      },
      "aggregations" : {
        "b" : {
          "terms" : {
            "field" : "b"
          }
        },
        "c" : {
          "sum" : {
            "field" : "c"
          }
        }
      }
    }
  }
}

zhangli

赞同来自:

谢谢你,符合我的要求,麻烦问下,知道用Java  api如何实现吗

Cheetah

赞同来自:

.addAggregation(AggregationBuilders.terms("a")
                .field("a").subAggregation(AggregationBuilders.terms("b").field("b"))
                        .subAggregation(AggregationBuilders.sum("c").field("c")
                        .order(Terms.Order.aggregation("c", false)

zhangli

赞同来自:

正确的应该是PC对应11111, WAP对应8
 
QQ截图20170912184005.png

 

要回复问题请先登录注册