Based on your query, which is selecting all nodes within a certain sub-tree in the repository, you will want to create an index that optimizes for path queries. Since your query does not filter based on properties but rather on the node’s position in the repository hierarchy, a path index is the most suitable. Here is a breakdown of the recommended steps to create a path index based on the AEM documentation:
- Access CRX DE: Open the CRX DE Lite tool to navigate the repository and create your index definition.
- Create the Index Definition Node: Navigate to the /oak:index node and create a new node for your custom index definition. You might name it something descriptive, such as homepageDescendants.
- Configure the Index: Set the properties for your index node:
- Set the jcr:primaryType to oak:QueryIndexDefinition.
- Set the type property to path.
- Set reindex to true if this is a new index or if you want to reindex.
- Add an includedPaths property and set it to [/content/homepage/jcr:content] to include only the descendants of this path.
- Reindex: After saving the changes, the new index will need to be reindexed. This is done automatically if reindex is set to true.
- Test the Query: Once reindexing is complete, test your query again to ensure that it is now using the new index.
Here’s an example of what the node structure for your index definition might look like in CRX DE:
<homepageDescendants
jcr:primaryType="oak:QueryIndexDefinition"
type="path"
reindex="true">
<indexRules jcr:primaryType="nt:unstructured">
<nt:base jcr:primaryType="nt:unstructured">
<properties jcr:primaryType="nt:unstructured">
<path jcr:primaryType="nt:unstructured"
name="jcr:path"
unique="false"/>
</properties>
</nt:base>
</indexRules>
<includedPaths jcr:primaryType="nt:unstructured">
<content jcr:primaryType="nt:unstructured" name="/content/homepage/jcr:content"/>
</includedPaths>
</homepageDescendants>This structure tells AEM to index the paths under `/content/homepage/jcr:content`, which should optimize your query. For further reading and more detailed instructions on how to create and manage custom indexes, you can refer to the following documentation: