How to query for empty collection in hibernate search

Also asked this question on stackoverflow, but wasn’t sure if it was better suited here.

We are using hibernate-search with ES back end. Parent class has multiple collection of different children objects. We can filter parents based on the value of the child as the collections are annotated with @IndexedEmbedded

We want to be able to filter parents based on if the collection of children is empty or not. We have tried using @IndexedEmbedded(indexNullAs = “null”) , and then filtering on queryBuilder.phrase().onField(“parent.children”).sentence(“null”).createQuery() , which has made no difference. Using the ES console we can show the parent, but when the collection is empty it isn’t listed at all, leading us to believe it hasn’t been indexed due to it being empty (not null).

Another option would be to filter on parent.collection.field using a wildcard, however this would not be recommended by the hibernate search docs due to the performance.

Hello,

Closing since I answered on stackoverflow (and others can as well): How to query for empty collection in hibernate search - Stack Overflow

No need to cross-post to get an answer, the team monitors both Stackoverflow and these forums.

Have a great day.