2 questions in relation to custom OAK indexes | Community
Skip to main content
jayv25585659
New Participant
April 30, 2025

2 questions in relation to custom OAK indexes

  • April 30, 2025
  • 1 reply
  • 304 views

1. How do I commit to my project code custom indexes for AEM 6.x? I've searched the net but nothing comes up.

 

2. Is there a way to easily translate a SQL2 to custom index XML? I found this site => https://oakutils.appspot.com/generate/index but the output available is JSON only. I'm wondering if XML output is available. I have not seen any Adobe guide or sample code where JSON is used to define a custom index.

 

Thanks for the help.

1 reply

AmitVishwakarma
New Participant
April 30, 2025

Hi @jayv25585659 ,

1. Committing Custom Oak Indexes in Your AEM 6.x Project

Where to put it:
Your custom index definitions belong under /oak:index in your content package, not under /apps or /libs. In a typical multi-module AEM Maven project that looks like:

 

ui.content/ └── src/ └── main/ └── content/ └── jcr_root/ └── oak:index/ └── myCustomIndex/ └── .content.xml

 

Example .content.xml:
A Lucene index that indexes the text property across all pages under /content/mysite:

 

<?xml version="1.0" encoding="UTF-8"?> <jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="oak:QueryIndexDefinition" type="lucene" compatVersion="{Long}2" async="[async]" <!-- run index build asynchronously --> includedPaths="[/content/mysite]" <!-- limit indexing to this path --> evaluatePathRestrictions="{Boolean}true" <!-- honors ACLs in queries --> reindex="{Boolean}true"> <!-- force a re-index on next startup --> <indexRules jcr:primaryType="nt:unstructured"> <nt:base jcr:primaryType="nt:unstructured"> <properties jcr:primaryType="nt:unstructured"> <text jcr:primaryType="nt:unstructured" name="text" propertyIndex="{Boolean}true" nodeScopeIndex="{Boolean}true" analyzed="{Boolean}true" /> </properties> </nt:base> </indexRules> </jcr:root>

 

Deploy it:

 

cd ui.content mvn clean install -PautoInstallPackage

 


On startup AEM will pick up /oak:index/myCustomIndex, detect reindex=true, and build your index.

2.Turning a SQL2 Query into a Custom Index XML

AEM 6.x only consumes XML under /oak:index. There’s no built-in JSON→XML converter, but here are foolproof methods:

Option A: Manual Mapping via Oak Utils

Generate JSON from your SQL2 on https://oakutils.appspot.com/generate/index

Copy the JSON fields into the XML template above, mapping:

type → jcr:root/@type

async → jcr:root/@async

includedPaths → jcr:root/@includedPaths

evaluatePathRestrictions → jcr:root/@evaluatePathRestrictions

indexRules…properties → <indexRules>…<properties>…</properties></indexRules>

Save as myCustomIndex/.content.xml and re-deploy.

 

Option B: CRXDE-Lite + Content Package

In CRXDE Lite, right-click /oak:index → Create → Oak QueryIndexDefinition.

Fill in the dialogs (type, paths, props)…

Build a content package from /oak:index/yourIndex.

Unzip the package and copy the generated .content.xml into your ui.content module under jcr_root/oak:index/.

Option C: oak-run Tool (JSON → Manual XML)

If you prefer CLI, download the Oak standalone JAR and run:

 

java -jar oak-run.jar indexGenerator \ --type lucene \ --includedPaths /content/mysite \ --properties name=text,propertyIndex=true,nodeScopeIndex=true,analyzed=true \ --output index.json

 

Then convert that JSON output into the .content.xml structure shown above.