Search AEM Content index in Elasticsearch
In the last blog post I gave a brief introduction into the integration of Elasticsearch1 into AEM. This followup will explain how the indexed data can be used in a search application in AEM. Although you can use every Elasticsearch client you want (e.g. the Java REST Client2), an easy way is the usage of one of the two Searches implemented in this package. Both Search classes (Search.java3 and PageSearch.java4) require an instance of the ElasticSearchService5.
Index AEM Content with Elasticsearch
With the build-in Lucene Index1 in AEM, most of the requirements for a flexible and fast search can be implemented with minimal effort and no need for additional dependencies. The functionality for queries is wrapped in the QueryBuilder API2 and the index configuration3 done in CRX. A query can search in multiple fields for values or full-text and provide scoring, excerpts etc. Depending on the supported languages, you can also configure Analyzers4 for Stemming, Stop Words etc.
AEM: Handling Page-Replication events with a custom Transport Handler
An usual approach to react to different events in AEM is the implementation of an Event Handler1. In your implementation you subscribe to one or more event topics which are then passed into the void handleEvent(Event event) method. The interface for an Event Handler is quite simple, so this is a very lean approach. You can find an example in Adobe’s Knowledge Base Although you can subscribe to the Replication Event2, there are some usecases where an EventHandler might not work for you.
Deploy Elasticsearch Rest Client into OSGi
Up until Elasticsearch 5.0.0 alpha 4 the official Elasticsearch Java client required the complete Elasticsearch distributable included in your application. Although there are several alternative clients available, the new Java Rest Client brings most of the functionallity bundled in a small package. Since the artifact published by elastic does not contain the required OSGi bundle information I created a wrapper you can find on Github1. Dependencies All dependencies are inherited from the RestClient and available as OSGi Bundles: