Hi,
I have some product nodes under this jcr path - /etc/products/mycompany/media.
The structure is as below -
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
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
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
.
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
andcostPerExecution
if needed, but they’re optional unless you want to fine-tune indexing behavior.
Place this XML under your project path:ui.apps/src/main/content/jcr_root/apps/mycompany/oak-index/mediaDescendantsIndex/.content.xml
Deploy the code to Cloud Manager pipeline.
Once deployed, verify indexing is complete using:
curl -u admin:admin http://localhost:4502/oak:index/mediaDescendantsIndex
Indexes all nt:unstructured
nodes under /etc/products/mycompany/media
Enables efficient execution of isdescendantnode(...)
queries
Avoids traversal warnings
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
.
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
andcostPerExecution
if needed, but they’re optional unless you want to fine-tune indexing behavior.
Place this XML under your project path:ui.apps/src/main/content/jcr_root/apps/mycompany/oak-index/mediaDescendantsIndex/.content.xml
Deploy the code to Cloud Manager pipeline.
Once deployed, verify indexing is complete using:
curl -u admin:admin http://localhost:4502/oak:index/mediaDescendantsIndex
Indexes all nt:unstructured
nodes under /etc/products/mycompany/media
Enables efficient execution of isdescendantnode(...)
queries
Avoids traversal warnings
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
Views
Likes
Replies
Views
Likes
Replies