How to Index a Node Name? | Community
Skip to main content
DhirajAg
Level 4
April 20, 2019

How to Index a Node Name?

  • April 20, 2019
  • 2 replies
  • 6001 views

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.

2 replies

Ravi_Pampana
Community Advisor
Community Advisor
April 20, 2019

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!

Gaurav-Behl
Level 10
April 20, 2019

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

DhirajAg
DhirajAgAuthor
Level 4
April 20, 2019

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"

                    }

               }

          }

     }

}

arunpatidar
Community Advisor
Community Advisor
April 20, 2019

Change reindex property to true

"reindex": true,

Arun Patidar