/**
*
* @return list
*/
public List<UserResponseVO> listConditionsAggregations() {
TermsAggregationBuilder builder = AggregationBuilders.terms("interests").field("interests");
SearchQuery query = new NativeSearchQueryBuilder()
.withQuery(QueryBuilders.matchQuery("lastName","smith")) //
.addAggregation(builder.subAggregation(AggregationBuilders.filter("interests",QueryBuilders.matchQuery("lastName","smith"))))
.build();
Aggregations aggregations = elasticsearchTemplate.query(query, new ResultsExtractor<Aggregations>() {
@Override
public Aggregations extract(SearchResponse response) {
return response.getAggregations();
}
});
List<UserResponseVO> list = new ArrayList<>();
Terms terms = aggregations.get("interests");
Iterator<Terms.Bucket> iterator = (Iterator<Terms.Bucket>) terms
.getBuckets().iterator();
while (iterator.hasNext()) {
MultiBucketsAggregation.Bucket bucket = iterator.next();
UserResponseVO user = new UserResponseVO((String) bucket.getKey(), (int) bucket.getDocCount());
list.add(user);
}
return list;
}