Expand my Community achievements bar.

SOLVED

oak indexing on aem 6.5 with nt base

Avatar

Level 8

Hi,

We have an xpath query for xml addon with the below  and want to create a new oak index

 

/jcr:root/content/app/us/en/productguide_Product_Reference_Guide//*[(jcr:contains(., 'battery'))] order by @jcr:score descending

 

I checked on https://oakutils.appspot.com/generate/index  

 

It showed the below . 

<?xml version="1.0" encoding="UTF-8"?><jcr:root xmlns:nt=http://www.jcp.org/jcr/nt/1.0 xmlns:jcr=http://www.jcp.org/jcr/1.0>

  <myIndex compatVersion="{Long}2" async="async" jcr:primaryType="oak:QueryIndexDefinition" evaluatePathRestrictions="{Boolean}true" type="lucene">

    <indexRules jcr:primaryType="nt:unstructured">

      <nt:base jcr:primaryType="nt:unstructured">

        <properties jcr:primaryType="nt:unstructured"/>

      </nt:base>

    </indexRules>

  </myIndex>

</jcr:root>

 

Is it good practice  to index the nt base like above without any named properties .Please suggest what could be alternative.

 

Note:- we are using the Adobe provided xml addon OOTB .

 

Regards,

Srinivas

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

If the following value battery(as mentioned in your queryis associated with any property and specific node type then you can use Explain query [http://localhost:7070/libs/granite/operations/content/diagnosistools/queryPerformance.html] to compare query performance between "/jcr:root/content/app/us/en/productguide_Product_Reference_Guide//*[(jcr:contains(., 'battery'))] order by @jcr:score descending" and the query with named property, specific node [/jcr:root/content/we-retail/language-masters//element(*,cq:PageContent)[@sling:resourceType="weretail/components/structure/page"] order by @jcr:score].

 

I feel it will help you optimize your query and finally you will be able to create requisite oak indexing.

 

Personally I always follow below points while writing any query -

  • Whenever possible, use CONTAINS instead of LIKE or '='. It should be your default choice when you need to find a specific text.
  • If a query seems to be slow, check its execution plan using Diagnosis Tool.
  • If you need more specific restrictions, use both CONTAINS and LIKE/equals.
  • Use a specific location.
  • Use a specific node type.

Please refer this : https://wttech.blog/blog/2020/jcr-query-performance/

View solution in original post

1 Reply

Avatar

Correct answer by
Employee Advisor

If the following value battery(as mentioned in your queryis associated with any property and specific node type then you can use Explain query [http://localhost:7070/libs/granite/operations/content/diagnosistools/queryPerformance.html] to compare query performance between "/jcr:root/content/app/us/en/productguide_Product_Reference_Guide//*[(jcr:contains(., 'battery'))] order by @jcr:score descending" and the query with named property, specific node [/jcr:root/content/we-retail/language-masters//element(*,cq:PageContent)[@sling:resourceType="weretail/components/structure/page"] order by @jcr:score].

 

I feel it will help you optimize your query and finally you will be able to create requisite oak indexing.

 

Personally I always follow below points while writing any query -

  • Whenever possible, use CONTAINS instead of LIKE or '='. It should be your default choice when you need to find a specific text.
  • If a query seems to be slow, check its execution plan using Diagnosis Tool.
  • If you need more specific restrictions, use both CONTAINS and LIKE/equals.
  • Use a specific location.
  • Use a specific node type.

Please refer this : https://wttech.blog/blog/2020/jcr-query-performance/