2

We are using Spring Data Elasticsearch Reactive Template

Query searchQuery = new NativeSearchQueryBuilder()
                .withQuery(queryBuilder)
                .withPageable(PageRequest.of(0, 10))
                .addAggregation(AggregationBuilders.terms("categories").field("category"))
                .build();

reactiveElasticsearchTemplate.search(searchQuery, documentType, IndexCoordinates.of(indexName))

In response we have Flux<SearchHit<T>> but there are no methods to retrieve aggregations.

How to retrieve the aggregations?

1 Answer 1

2

The ReactiveElasticsearchTemplate has aggregate methods.

See the corresponding API interface

There is no combination of the single entities in a flux and the aggregations in the reactive part.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you, I also found this pull request github.com/spring-projects/spring-data-elasticsearch/pull/203
This PR is about parsing the aggregation data, but it only considers StringTerms and LongTerms buckets, but aggregations are much more complex. For Spring Data Elasticsearch to support parsing aggregations, we would need to handle far more cases of aggregations. So at the moments we just return the Elasticsearch aggregations.
So, in case we want to return both hits and aggregations, we need to call 2 methods which each will return Flux<T> and than to combine these 2 Flux<T> into 1 Flux<T>, is this correct?
search returns Flux<SearchHit<T>> and aggregate returns Flux<Aggregation>. The returned types a different, aggregation objects are no entities

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.