Expand my Community achievements bar.

Join expert-led, customer-led sessions on Adobe Experience Manager Assets on August 20th at our Skill Exchange.
SOLVED

AEMaaCS - How to create OAK index for all nodes under a path by node name

Avatar

Level 3

Hi,

I have some product nodes under this jcr path - /etc/products/mycompany/media. 

The structure is as below -

prithwi_0-1750104118545.png

 

I ran a query to find all leaf nodes under a specific path like /etc/products/mycompany/media/2183. My query is this which returns all nodes correctly. But due to large number of nodes I'm getting Traversal query warning. So I wanted to create oak index to optimize this query. However, query doesn't contain any property to specify in the index. So can anyone suggest index definition for this query? 

select * from [nt:unstructured] as a where isdescendantnode(a, "/etc/products/mycompany/media/2183") 

Please note that I'm using AEM cloud service.

 

Thanks

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @prithwi,

Create a Custom Oak Index for Path Restriction

Since your query is only using isdescendantnode, you can create a path-restricted index that indexes nt:unstructured nodes under /etc/products/mycompany/media.

Here’s how you can define this index via a custom OAK index definition under /apps.

Create Index Definition: Example Structure

Place this under:

/apps/mycompany/oak-index/mediaDescendantsIndex/.content.xml

mediaDescendantsIndex - Index Definition

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root
    xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
    xmlns:jcr="http://www.jcp.org/jcr/1.0"
    xmlns:oak="http://jackrabbit.apache.org/oak/ns/1.0"
    jcr:primaryType="oak:QueryIndexDefinition"
    jcr:title="Index for media descendant nodes"
    type="lucene"
    async="async"
    evaluatePathRestrictions="{Boolean}true"
    compatVersion="{Long}2"
    includedPaths="[/etc/products/mycompany/media]"
    indexRules="[nt:unstructured]"
    reindex="{Boolean}true">
</jcr:root>

Note: You can also add costPerEntry and costPerExecution if needed, but they’re optional unless you want to fine-tune indexing behavior.

Deployment Steps (AEM Cloud Service)
  1. Place this XML under your project path:
    ui.apps/src/main/content/jcr_root/apps/mycompany/oak-index/mediaDescendantsIndex/.content.xml

  2. Deploy the code to Cloud Manager pipeline.

  3. Once deployed, verify indexing is complete using:

This will help you to know:
  • Indexes all nt:unstructured nodes under /etc/products/mycompany/media

  • Enables efficient execution of isdescendantnode(...) queries

  • Avoids traversal warnings


Santosh Sai

AEM BlogsLinkedIn


View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @prithwi,

Create a Custom Oak Index for Path Restriction

Since your query is only using isdescendantnode, you can create a path-restricted index that indexes nt:unstructured nodes under /etc/products/mycompany/media.

Here’s how you can define this index via a custom OAK index definition under /apps.

Create Index Definition: Example Structure

Place this under:

/apps/mycompany/oak-index/mediaDescendantsIndex/.content.xml

mediaDescendantsIndex - Index Definition

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root
    xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
    xmlns:jcr="http://www.jcp.org/jcr/1.0"
    xmlns:oak="http://jackrabbit.apache.org/oak/ns/1.0"
    jcr:primaryType="oak:QueryIndexDefinition"
    jcr:title="Index for media descendant nodes"
    type="lucene"
    async="async"
    evaluatePathRestrictions="{Boolean}true"
    compatVersion="{Long}2"
    includedPaths="[/etc/products/mycompany/media]"
    indexRules="[nt:unstructured]"
    reindex="{Boolean}true">
</jcr:root>

Note: You can also add costPerEntry and costPerExecution if needed, but they’re optional unless you want to fine-tune indexing behavior.

Deployment Steps (AEM Cloud Service)
  1. Place this XML under your project path:
    ui.apps/src/main/content/jcr_root/apps/mycompany/oak-index/mediaDescendantsIndex/.content.xml

  2. Deploy the code to Cloud Manager pipeline.

  3. Once deployed, verify indexing is complete using:

This will help you to know:
  • Indexes all nt:unstructured nodes under /etc/products/mycompany/media

  • Enables efficient execution of isdescendantnode(...) queries

  • Avoids traversal warnings


Santosh Sai

AEM BlogsLinkedIn


Avatar

Level 3

Thanks Santosh for your detail solution. It worked for me.

The magic resides in these two properties that I was missing before.

evaluatePathRestrictions="{Boolean}true"
includedPaths="[/etc/products/mycompany/media]"
indexRules="[nt:unstructured]"

Thank you