Search code examples
hibernateelasticsearchhibernate-search

Hibernate Search: groupby and in clause


What are the equilivalent of the groupby and In SQL clause in an Hibernate Search Query?

Thanks


Solution

  • There is no direct equivalent. If you need to group the hits after a query, then you probably queried the wrong index. If I remember correctly your last question was about a product that has multiple prices, and you were querying the prices, which index-embed the product. Try the opposite: query the product, and index-embed the prices.

    If your problem is that only one of the prices is actually relevant to a particular user, and you need to filter out other prices, then you need nested search, and that is only available starting with Hibernate Search 6.

    If all you need is a count of hits grouped by category, then you might be interested in Hibernate Search 6's aggregations. They are available in Hibernate Search 5 too, but with a different API, and they are named facets and are more limited (no support for multi-valued fields in particular).