| There are way too many aggregations for us to support them all through the query DSL. To address use cases beyond the most simple ones, we need a way for users to define aggregations using JSON, and receive a JSON-formatted string as a result. Something like:
AggregationKey<String> myAggregationKey = AggregationKey.of( "myAggregation" );
SearchResult<Book> result = Search.session( entityManager ).search( Book.class )
.extension( ElasticsearchExtension.get() )
.predicate( f -> f.matchAll() )
.aggregation( priceFacetsKey, f -> .fromJson( "{\"histogram\":{...}}" ) )
.fetch( 100 );
As a second step, we may want to allow users to pass an object that will extract data from the response:
AggregationKey<MyBean> myAggregationKey = AggregationKey.of( "myAggregation" );
SearchResult<Book> result = Search.session( entityManager ).search( Book.class )
.extension( ElasticsearchExtension.get() )
.predicate( f -> f.matchAll() )
.aggregation( priceFacetsKey, f -> .fromJson(
"{\"histogram\":{...}}",
c -> new MyBean( doSomeParsing( c.getJson() ) )
) )
.fetch( 100 );
We will need a similar feature for projections, but these will be a bit harder since there are many ways to project. |