Negate a Query Constraint

You can use the negate() method to invert any constraint in an HstQuery. This allows you to exclude results that match a specific condition.

For example, to retrieve documents that do not contain the term "hippo":

// Query documents that do not contain "hippo" final HstQuery query = HstQueryBuilder.create(scope) .ofTypes(BaseDocument.class) .limit(10) .where(constraint(".").contains("hippo").negate()) .build();

In this example, the negate() method inverts the .contains("hippo") constraint. The query returns up to 10 documents of type BaseDocument that do not contain the word "hippo".

Share Feedback
Page: /build/search/jcr-search/negating-a-hstquery-filter
Section: Build
Category *