How to Index a Node Name? | Community
Skip to main content
DhirajAg
Level 4
Apr 20, 2019 3:40 AM UTC

How to Index a Node Name?

I have a query where I am trying to find a node through its name. My sample query is below

SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/content/abc]) and NAME(s) = 'testNode'

I am trying to find nodes under /content/abc with the name as 'testNode' and I get in the log that i should try to index it. How can i achieve this? Can you share a sample index definition for indexing a node name?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

5 replies

Gaurav-Behl
Level 10
Apr 20, 2019 9:34 AM UTC

Create a lucene index as mentioned in the link shared by Ravi, set 'indexNodeName' and  evaluatePathRestrictions to true

- compatVersion = 2

  - async = "async"

  - jcr:primaryType = oak:QueryIndexDefinition

  - evaluatePathRestrictions = true    // to index node names under a specific path like /content/abc

  - type = "lucene"   

  + indexRules

   + nt:base        //   this is your node name that you want to index/run query against

   - indexNodeName = true   // to index node names

    + properties                      

Jackrabbit Oak – Lucene Index

Oak Utilities : Index Definition Generator

Translate
DhirajAg
DhirajAgAuthor
Level 4
Apr 20, 2019 5:59 PM UTC

Hi Gaurav,

I have tried the same and it is not working for me. I stil get the error to consider creating an index.

Here is my query

select [jcr:path], [jcr:score], * from [nt:base] as a where name(a) = 'audience' and isdescendantnode(a, '/apps/weretail/components/templates/testpage')

and my index definition below

{

     "jcr:primaryType": "oak:QueryIndexDefinition",

     "compatVersion": 2,

     "type": "lucene",

     "async": "async",

     "evaluatePathRestrictions": true,

     "reindex": false,

     "reindexCount": 14,

     "indexRules": {

          "jcr:primaryType": "nt:unstructured",

          "audience": {

               "jcr:primaryType": "nt:unstructured",

               "indexNodeName": true,

               "properties": {

                    "jcr:primaryType": "nt:unstructured",

                    "path": {

                         jcr:primaryType": "nt:unstructured",

                         "ordered": true,

                         "propertyIndex": true,

                         "name": "path"

                    }

               }

          }

     }

}

Translate
arunpatidar
New Participant
Apr 20, 2019 10:52 PM UTC

Change reindex property to true

"reindex": true,

Translate
Arun Patidar
Ravi_Pampana
New Participant
Apr 20, 2019 7:39 AM UTC

Hi,

You can check below link for creating custom index in aem

Oak Queries and Indexing

Instead of finding the node try to query using resourceType if available, as node name might have random number when same component is used more than once under a node, also using resourceType will have oak:index already available and no custom index need to be added.

Using type = cq:pagecontent (primary type of jcr:content) property in query builder will improve load time and also add p.guesstotal= true as a best practice.

Hope this helps!

Translate