我有一个JSON查询版本,将两个字段的总和相加-
"aggs": {
"field1Sum": {
"sum": {
"field": "field1"
}
},
"field2Sum": {
"sum": {
"field": "field2"
}
}
}
我需要使用Java QueryBuilder for Elasticsearch将数据转换为此查询
至今 -
SumBuilder s1 = AggregationBuilders.sum(field2Sum).field(field2);
SumBuilder s2 = AggregationBuilders.sum(field1Sum).field(field1);
有什么帮助吗?
最佳答案
SearchResponse sr = client.prepareSearch()
.setQuery(QueryBuilders.matchAllQuery())
.addAggregation(
AggregationBuilders.sum(field2Sum).field(field2)
)
.addAggregation(
AggregationBuilders.sum(field1Sum).field(field1)
)
.get();
Link
关于java - 在Elasticsearch中添加多个总和,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44315065/