We're updating the issue view to help you get more done. 

Define aggregations from JSON with Elasticsearch

Description

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:

1 2 3 4 5 6 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:

1 2 3 4 5 6 7 8 9 10 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\":{...}}", // Use a context object so that we can later consider providing helpers, or access to the whole response 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.

Environment

None

Status

Assignee

Unassigned

Reporter

Yoann Rodière

Labels

None

Suitable for new contributors

None

Pull Request

None

Feedback Requested

None

Components

Fix versions

Priority

Major