1

我有一个 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);

有什么帮助吗?

4

1 回答 1

1
SearchResponse sr = client.prepareSearch()
    .setQuery(QueryBuilders.matchAllQuery())
    .addAggregation(
            AggregationBuilders.sum(field2Sum).field(field2)
    )
    .addAggregation(
            AggregationBuilders.sum(field1Sum).field(field1)
    )
    .get();

关联

于 2017-06-02T08:29:46.727 回答