"Composite Aggregation" Possibility Question


I wonder if there’s something like an aggregation for multiple combined values within the Hibernate Search 6 API. To me it looks like the API only supports one single field (or multiple different unconnected fields).

Is the following Example possible with the new aggregation or composite APIs? A quick NO would also be accepted, as this use case with a group by seems to belong more to SQL-Like queries and not a search database

(stupid) Example:

{ name: "Hans", title: "Dr.", value: 1}
{ name: "Hansi", title: "Dr.", value: 1} 
{ name: "Franz", title: "none", value: 2} 

I would want to query by aggregated by value and title combinded with a result that reads as follows:

{  title: "Dr.", value: 1, count: 2, name: ["Hans", "Hansi"] }
{  title: "none", value: 2, count: 1, name: ["Franz"] }


That’s not possible (yet) with the Hibernate Search API.

However, if you use the Elasticsearch backend, you can use the Elasticsearch extension to define your aggregation as JSON and retrieve results as JSON. That should allow you to do anything Elasticsearch has to offer.

I think what you’re looking for here is a terms aggregation on field title with a sub-aggregation: another terms aggregation, this time on field name. You’ll get a count of documents per title, then for each title you’ll get a count of documents per name.

1 Like