Missing predicate is missing

I’am trying to filter some content based on whatever is has some defined Id or none.
Something like this:

b.should(f.match().field(“groups.topic.id”).matching(topicId));
b.should(f.missing().field(“groups”));
b.minimumShouldMatchNumber(1);

I’ve seen on HSEARCH-2464 that the “missing” predicate is suposed to be implemented but it’s not and the @IndexedEmbedded.indexNullAs was removed as well. There’s any other way I can achieve what I Ineed? When the “missing” predicate is going to be implemented?

I’m using hibernate-search 6.0.0beta10
Thanks

As explained here:

There isn’t any built-in predicate to match documents for which a given field is null, but you can easily create one yourself by negating an exists predicate.

This can be achieved by using an exists predicate in a mustNot clause in a boolean predicate, or in an except clause in a matchAll predicate.

So in your case:

b.should(f.match().field(“groups.topic.id”).matching(topicId));
b.should(f.matchAll().except(f.exists().field(“groups”)));
b.minimumShouldMatchNumber(1);
1 Like

Ok, it was definitely too early when I wrote my answer :slight_smile: I edited with a solution that actually does what you want, i.e.:

b.should(f.match().field(“groups.topic.id”).matching(topicId));
b.should(f.matchAll().except(f.exists().field(“groups”)));
b.minimumShouldMatchNumber(1);
1 Like

Thanks for the fast replay and sorry for only replying now. It worked perfectly.