Friday, January 27, 2017

How to create and package the Oak index in AEM 6?


Issue: If you see some warnings like below in error.log, then its time to create index for improving jcr search performance

*WARN* [0:0:0:0:0:0:0:1 [1485528947344] GET /bin/services/rsa/profile.json HTTP/1.1] org.apache.jackrabbit.oak.spi.query.Cursors$TraversingCursor Traversed 26000 nodes with filter Filter(query=select [jcr:path], [jcr:score], * from [nt:unstructured] as a where [userid] like '_%' and [securityservice] like 'rsa' and isdescendantnode(a, '/profile') /* xpath: /jcr:root/profile//element(*, nt:unstructured)[(jcr:like(@userid, '_%') and jcr:like(@securityservice, 'rsa'))] */, path=/profile//*, property=[userid=[(_%..], securityservice=[rsa]]); consider creating an index or changing the query


Steps

1) Identify the potential properties that need to be indexed.

2) Create _oak_index folder and add the content xml for creating oak index definition nodes.

Path: /your_module/src/main/content/jcr_root/_oak_index/.content.xml


<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:oak="http://jackrabbit.apache.org/oak/ns/1.0" xmlns:slingevent="http://sling.apache.org/jcr/event/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0" xmlns:dam="http://www.day.com/dam/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal"
    jcr:mixinTypes="[rep:AccessControllable]"
    jcr:primaryType="nt:unstructured">
    <userid
        jcr:primaryType="oak:QueryIndexDefinition"
        propertyNames="{Name}[userid]"
        reindex="{Boolean}false"
        type="property"/>
    <securityservice
        jcr:primaryType="oak:QueryIndexDefinition"
        propertyNames="{Name}[securityservice]"
        reindex="{Boolean}false"
        type="property"/>      
</jcr:root>

2) Add the paths in filter.xml

  <filter root="/oak:index/userid"/>
  <filter root="/oak:index/securityservice"/>

This will create Oak index below node /oak:index. You can also use CRXDE to create index. 



Ref: https://docs.adobe.com/docs/en/aem/6-0/deploy/upgrade/queries-and-indexing.html


1 comment: