How many times is an AEM Component used in the JCR?

Can we detect and remove unused components from our codebase? Is this AEM component being used at all? How many times is my component used within my running AEM instance?

These are the common questions we have when we are trying to figure out the number of use and the node-paths of the targeted searched component within the Java content repository, known as “JCR”. In this article, you will discover one of the quickest techniques used to retrieve the total number of uses and node-paths of a component within the JCR by using the Query Builder API, query debugger tool.

If you don’t have certain user priveledges within your AEM instance, there’s another way to find out the usage of your component(s), Components Console; however, the Components Console is restricted in a sense where the component search results-list only display pages of a given component and does not provide a total number of how many pages are returned from the search.


1. Component Search by the Query Builder API, Query Builder Debugger Tool

The AEM Query Builder is an API which can be used to search for nodes in JCR. Well defined “Predicates” are typically created from using the Query Builder Debugging Tool, as this tool serves instant search results within the UI.

Step 1: With your running AEM instance, visit http://localhost:4502/libs/cq/search/content/querydebug.html.

Step 2: Paste in the search query below & hit search; view screenshot.
Replace with your component’s path: weretail/components/content/heroimage
Note!: sometimes the descendant path must be more nested, so /content/we-retail/gb/en

1
2
3
path=/content/we-retail
1_property=sling:resourceType
1_property.value=weretail/components/content/heroimage

This query searches for all types of nodes with the sling:resourceType equals to the value, weretail/components/content/heroimage, and where the path is descendant from /content/we-retail; to learn more about the Query builder API and queries, click here (Adobe Documentation)

Step 3: Review the results.
Query Builder Debugger

Extra:

Find out How many pages are using an AEM template?

The query below will find all cq:Page nodes in the JCR, which cq:template equals to /conf/we-retail/settings/wcm/templates/hero-page; under the content path /content/we-retail. The search results will show you the absolute node page path of whom has the matched property and value set.

1
2
3
4
type=cq:Page
path=/content/we-retail
1_property=jcr:content/cq:template
1_property.value=/conf/we-retail/settings/wcm/templates/hero-page

Ensuring that the “path” property is set is important, because you would not want to excessively triverse through the entire JCR; which will exhaust the AEM environment performance.

Extra:

How to search for all nodes in AEM, JCR, with an existing property?

The query below will search all nodes in the JCR, which “myCustomProperty” exists; under the content path /content/we-retail. The search results will show you the absolute node page path of whom has the matched property and value set.

1
2
3
path=/content/we-retail
property=myCustomProperty
property.operation=exists

Ensuring that the “path” property is set is important, because you would not want to excessively triverse through the entire JCR; which will exhaust the AEM environment performance.


2. Component Search by the Components Console

This out of the box Components Console, CC, is available from AEM 6.2+ right under Tools -> General -> Components. The CC displays search results in a form of pages where the component is being used; rather than each node from the example above. This console is accessible to authors so that even they can check for which pages use the searched component.

Step 1: Within your running AEM instance, visit http://localhost:4502/libs/wcm/core/content/sites/components.html.

Step 2: Search for a component. Insert your search criteria with either by “keyword”, “component path”, or “component group”. On every change of the search criteria, you should see results in a list format on the right hand side of the search left side bar.
Step 3: Click on the targeted component, and you will be redirected to the details page.
Step 4: From the details page, click on “live usage”, and a results-list of pages will be displayed, where the targeted component can be found.
Step 5: From the results-list, clicking on a link will open the page’s editor.

Components Console – Steps 2 & 3Components Console - Steps 2 & 3 Components Console – Steps 4 & 5 Components Console - Steps 4 & 5

Was this Article Helpful?

Certified AEM Developer who has been working on AEM software developer for the past 5 years.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top