Property Index in AEM - Index properties and steps to create custom index
Property Index is for queries involving property constraints - equality, exist/not null check on property.
Oak property Index:
Oak property Index:
- Node of type "oak:QueryIndexDefinition" with
Steps to create custom property index:
- Sample query involving property constraint - Get all live copy pages which has overwritten the properties/which has cq:propertyInheritanceCancelled
- path=/content/we-retail
- type=cq:Page
- 1_property=@jcr:content/cq:propertyInheritanceCancelled
- 1_property.operation=exists
- p.limit=-1
- "Explain Query" response for the above query :
- Now is the time to create Property Index for the property - cq:propertyInheritanceCancelled
- Navigate to CRXDE -> /oak:index node
- Being on oak:index node, Create new node of
- name -> cqPropertyInheritanceCancelled (in par with naming convention of OOB indexes)
- type -> oak:QueryIndexDefinition
- Add below mandatory properties
Name Type Value type String property propertyNames Name[] cq:propertyInheritanceCancelled - Behind the scene: Property Index works in Synchronous mode of Indexing, the moment index definition is persisted, it will start indexing the related content.
- On "Refresh" of newly created index node -> below two properties are reflected automatically
- Note:
- Refresh to reflect the properties that are automatically created.
- New property index node along with two mandatory properties to be persisted in one shot. We will get exception otherwise - highlighted in demo video below
- Execute sample query again and observe the index used:
- Observation/Conclusion:
- For a query involving property constraint, if both property and lucene index is available -> In general, Property Index will be picked. (Cost value is low for property index compared to lucene index as evident from the above screenshot for this use case)
- Initially when we executed the query without property index, lucene index related to the type(cq:Page) we used in the query is picked which is "cqPageLucene"
Name | Type | Value |
reindex | Boolean | false |
reindexCount | Long | 1 |
With this, we are done with creating Property Index for a specific property with mandatory properties.
Usage of other supporting properties in a Property Index will be drafted in next follow up post with video demo for better clarity.
Reindexing Property Index:
- One of the possible cause for reindexing is, change in the existing index definition. Reindexing can be done in two ways for a Property Index.
- Synchronous way
- By updating reindex property to true.
- Once it is finished indexing, it will automatically set it back to false with an update to reindexCount value(value will be incremented by 1 from the existing value)
- Asynchronous reindexing
- Property index updates is assigned to a dedicated background job and when the indexing is done, the property definition will be switched back to synchronous updates mode
- To enable this,
- Note: Both these updates to be persisted in one shot (do not trigger save with one property update)
- As a result of this, below property would be automatically created.
- Navigate to JMX console - http://localhost:4502/system/console/jmx and invoke the MBean - PropertyIndexAsyncReindex#startPropertyIndexAsyncReindex.
- Once when the job is completed,
- automatically created property async will be removed
- reindex property would be set to false
- reindexCount would be incremented to 1 from its existing value.
Action | Name | Type | Value |
Add | reindex-async | Boolean | true |
Update (value from false->true) | reindex | Boolean | true |
Name | Type | Value |
async | String | async-reindex |
Video Demo:
- Creating Property Index for cq:propertyInheritanceCancelled:
- Property Index reindexing - Asynchronous
Comments
Post a Comment