我有一个json查询版本,在这样的聚合中添加两个字段的总和 -
DownloadManager downloadManager = DownloadManager.class.cast(getSystemService(DOWNLOAD_SERVICE));
Uri uri = downloadManager.getUriForDownloadedFile(id);
我需要使用Java QueryBuilder for Elasticsearch将我的数据转换为此查询
到目前为止 -
"aggs": {
"field1Sum": {
"sum": {
"field": "field1"
}
},
"field2Sum": {
"sum": {
"field": "field2"
}
}
}
任何帮助?
答案 0 :(得分:1)
SearchResponse sr = client.prepareSearch()
.setQuery(QueryBuilders.matchAllQuery())
.addAggregation(
AggregationBuilders.sum(field2Sum).field(field2)
)
.addAggregation(
AggregationBuilders.sum(field1Sum).field(field1)
)
.get();