{
"query": {
"bool": {
"must": [
{
"term": {
"id": {
"value": 1111
}
}
}
]
}
},
"aggs": {
"sequence": {
"terms": {
"field": "sequence.keyword"
},
"aggregations": {
"amount": {
"sum": {
"field": "amount"
}
}
}
},
"totalAmount": {
"sum_bucket": {
"buckets_path": "sequence>amount"
}
}
}
}
Spring Data ElasticSearch 3.2
final SearchQuery searchQuery =
new NativeSearchQueryBuilder()
.withQuery(QueryHelper.boolQueryBuilder(id))
.addAggregation(
terms("sequence")
.field("sequence.keyword")
.subAggregations(subAggregations()))
.addAggregation(sumBucket("sum_bucket", "sequence>amount"))
.build();
Now, since addAggregation method of NativeSearchQueryBuilder accepts AbstractAggregationBuilder and sumBucket is of type PipelineAggregationBuilder, not able to pass this value to addAggregation(sumBucket("sum_bucket", "sequence>amount")) due to compilation error, Any idea how to use sumBucket on terms aggregation and write in java?
I just checked the code of Spring Data Elasticsearch and Elasticsearch itself. Using PipelineAggregationBuilder
derived aggregations currently is not possible with Spring Data Elasticsearch.
I don't know, why Elasticsearch has two different class hierarchies for aggregations, but Spring Data Elasticsearch currently can only handle AggregationBuilder
and not PipelineAggregationBuilder
derived classes.
I created an issue in Jira for this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.