Lessons
  Menu

Understanding and Using AEM’s QueryBuilder Tool

Adobe Experience Manager (AEM) offers a powerful tool known as the QueryBuilder, which provides a flexible and convenient way to perform complex searches and operations within the Java Content Repository (JCR). It allows developers and administrators to construct and run queries without deep knowledge of the underlying query languages like SQL2 or XPath.

What is QueryBuilder?

QueryBuilder is a Java API and a RESTful service in AEM designed for simplifying the process of creating and executing queries against the JCR. It uses a key-value pair structure to define query criteria, making it more accessible than traditional JCR query languages.

How to Use QueryBuilder Tool

The QueryBuilder tool in Adobe Experience Manager (AEM) can be accessed through its HTTP API, typically via a URL structured in a specific format. The general format of the URL to access the QueryBuilder is: ‘http://[YOUR_AEM_SERVER]:[PORT]/libs/cq/search/content/querydebug.html

Examples of QueryBuilder Usage

Let’s explore some practical examples to demonstrate how QueryBuilder can be used:

Finding All Pages Under a Path

Query Description: Retrieve all pages under a specific content path.

QueryBuilder Syntax:

type=cq:Page
path=/content/we-retail
p.limit=-1

Explanation: This query finds all nodes of type cq:Page under the path /content/we-retail. The p.limit=-1 parameter ensures all matching results are returned.

Searching for Text in Page Titles

Query Description: Search for pages whose titles contain a specific text.

QueryBuilder Syntax:

type=cq:Page
path=/content/we-retail
fulltext=Summer Collection
property=jcr:content/jcr:title
p.limit=-1

Explanation: This query searches for pages in /content/we-retail where the jcr:title property of the jcr:content node (page title) contains the phrase “Summer Collection”.

Filtering Components by Resource Type

Query Description: Find all components of a specific sling:resourceType.

QueryBuilder Syntax:

type=nt:unstructured
path=/content/we-retail
property=sling:resourceType
property.value=weretail/components/content/image
p.limit=-1

Explanation: This query finds all unstructured nodes (nt:unstructured) under /content/we-retail that are of the resource type weretail/components/content/image.

Querying Pages Modified After a Certain Date

Query Description: Find pages that were last modified after a specific date.

QueryBuilder Syntax:

type=cq:Page
path=/content/we-retail
daterange.property=jcr:content/cq:lastModified
daterange.lowerBound=2022-01-01T00:00:00
daterange.lowerOperation=>=
p.limit=-1

Explanation: This query selects pages under /content/we-retail that have a cq:lastModified date greater than or equal to January 1, 2022.

Conclusion

QueryBuilder in AEM is a versatile and user-friendly tool for querying the JCR. It abstracts the complexities of JCR query languages, offering a more straightforward approach to retrieving data. By understanding and utilizing the examples provided, users can perform a wide range of queries to effectively manage and interact with the content stored in AEM. Whether you’re a developer or an AEM administrator, mastering QueryBuilder can significantly enhance your capability to interact with AEM’s JCR.