We have been using the hibernate-search for a while with springboot.
Have a Question on nested predicate use for longer hierarchy of nesting...
Till 6.1.5 we are using the below syntax to query a nested object chain:
List<Address> hits = searchSession
.search(Address.class)
.where(f ->
f
.nested().objectField("customer").nest(
f
.bool()
.must(
f
.nested().objectField("customer.wishLists").nest(
f.bool().must(
f.nested().objectField("customer.wishLists.products").nest(
f.match().field("customer.wishLists.products.title").matching("Nestle"))
)
)
)
)
)
.fetchHits(page.getPageNumber() * page.getPageSize(), page.getPageSize());
with 6.2's nested predicate improvement can we nest all the chain in one step :
example:
List<Address> hits = searchSession
.search(Address.class)
.where((f, root) -> {
root.add(f.matchAll());
f.nested("customer.wishLists.products")
.add(
f.match().field("customer.wishLists.products.title").matching("Nestle")
);
})
.fetchHits(page.getPageNumber() * page.getPageSize(), page.getPageSize());
Or do we need to nest through individual objects like:
List<Address> hits = searchSession
.search(Address.class)
.where((f, root) -> {
root.add(f.matchAll());
f.nested("customer")
.add(
f.nested("customer.wishLists")
.add(
f.nested("customer.wishLists.products")
.add(
f.match().field("customer.wishLists.products.title").matching("Nestle")
)
));
})
.fetchHits(page.getPageNumber() * page.getPageSize(), page.getPageSize());
Explained in the Question
Nesting all in one step should have worked in 6.1 too.
And in fact... when you only have one predicate like in your example, you don't need nesting at all. You can rely on implicit nesting.
Or in 6.2:
Explicit nesting is only useful when you have two or more predicates, and want to match only when those two predicates match on the same object. See https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#search-dsl-predicate-nested.