Finding Content Without a Tag With AEM Query Builder

Olav Ahrens Rotne 4ennrbj1svk Unsplash

Recently, I came across a requirement where we needed to build a complex query. The query was all the combinations of the title predicate, date predicate, and tags predicates to search for the page results.

One of the parts in the given requirement was to search the pages that did not include a specific tag. Let’s check out a simple example.

In this example, there are three demo pages (demo-page-1, demo-page-2 and demo-page-3), each containing some specific tags.

Aem crxde page hierarchy

I have applied two tags on demo-page-1. In the same way, I have applied the tags for other two pages also.

Aem page properties Page1 Tags

Adobe - Content for Everyone
Content for Everyone

Companies that can quickly and consistently meet the demands of consumers are thriving in an era of infinite content. Learn about how to build fluid experiences for your omnichannel customers.

Get the Guide

Now, I want to search the pages which don’t include the tag tagsearch:model/sampleModel1. So, by using the property operation unequals, I found the query works perfectly fine if only one tag is assigned to the page. For instance, only tagsearch:model/sampleModel1 present in the cq:tags page property.

Aem Query Builder Unequals

In the above screenshot, I was getting the perfect result. The demo-page-1 was excluded from the result, which was expected. But, when there were multiple tags assigned, the cq:tags property of the page as shown in previous image. The results were not as expected. The results included the demo-page-1 and I was expecting the result to exclude that page as the tag present there.

How-To Resolve

To resolve this issue, I applied one workaround. I created the query like this:


It worked for me and I got the expected results of what I was looking for.

Aem Query Negation

We can use the above query example according to our requirement to create the query map. Therefore, we can write the conditions. For instance, if the property contains cq:tags and the operation is unequal, then we can create the query like the below:


The 100_group is just a random text to make the (1_group.100_group) group unique, so that the 1_group.100_group.p.not=true will not be effected by the other group that is using it in the query builder.


In the above example, 1_group.100_group.p.not=true won’t negate 1_group.1_property=jcr:content/pageTitle results.

I hope you for this blog useful. Don’t forget to drop a comment in the section below if you need more help with this solution. Be sure to check out our entire Adobe blog collection for more helpful tips and tricks.

About the Author

Rahul is Adobe Experience Manager Developer.

More from this Author

Thoughts on “Finding Content Without a Tag With AEM Query Builder”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up