想使用ES作为数据库,使用java api调用,需要group by一个Field,同时对多个Field做sum、avg等等,但是发现只有TermsBuilder有subAggregation方法,可以添加子聚合,SumBuilder,AvgBuilder都不能添加subAggregation?
使用SQL语句表达类似于:
有人遇到过这种情况吗,是怎么解决的?
使用SQL语句表达类似于:
select field1,sum(field2),sum(field3) from table group by field1
有人遇到过这种情况吗,是怎么解决的?
1 个回复
weizijun - elasticsearch fan
赞同来自:
"from": 0,
"size": 0,
"_source": {
"includes": [
"field1",
"SUM",
"SUM"
],
"excludes":
},
"fields": "field1",
"aggregations": {
"field1": {
"terms": {
"field": "field1",
"size": 200
},
"aggregations": {
"SUM(field2)": {
"sum": {
"field": "field2"
}
},
"SUM(field3)": {
"sum": {
"field": "field3"
}
}
}
}
}
}