Liferay 7 Remote ElasticSearch
Liferay 7 Remote ElasticSearch

A little bit history at the beginning. There were 2 search implementations in Liferay 6. By default built-in Lucene was used for indexing and searching information. But, as many other modules in Liferay, search functionality was implemented via unified interface, so, it was possible to implement other search solutions. So, another integration was based on Apache Solr, installed as remote server. Implementation with Sorl usually was used in clustered configurations.

In Liferay 7/DXP ElasticSearch used as a default search engine. And now it is possible to use same implementation for both - "local" installation, then search engine started inside Liferay and with "remote" installation, then search engine installed on remote server and Liferay (or several Liferays in cluster) used it.

So, by default Liferay run ElasticSearch in "local" mode. It is simple for starting, but not recommended to be used in production mode (speaking more -  it is not official supported in DXP) because of many reasons:

  • in local mode ElasticSearch started in same JVM as Liferay, so - both products may affect each other,
  • in local mode it is not possible to build cluster (several Liferay portals should use one ElasticSearch),
  • actually, for production it is good idea to cluster ElasticSearch itself.

So, lets look that we need to do to configure Liferay to use ElasticSearch in remote mode.

I'm assuming you already have Liferay 7.0.4 GA5 and it is already using ElasticSearch "by default", local mode.

Install and configure ElasticSearch

Lets look on default basic ElasticSearch installation required for Liferay (clustering and production tuning of ElasticSearch and a subject for another big article).

We will need ElasticSearch ElasticSearch 2.4.x (you can download it here - https://www.elastic.co/downloads/past-releases). For current moment latest version is 2.4.6 (you can download it here - https://www.elastic.co/downloads/past-releases/elasticsearch-2-4-6). 2.4 - is a latest version of ElasticSearch officially supported by Liferay 7.0.4 and DXP SP4+ (FP22+) (maybe it will work with ElasticSearch 5.x or 6.x - but I did not checked).

So, download archive and unpack it.

For ElasticSearch configuration we will need to edit file <elastichome>/config/elasticsearch.yml and write there:

cluster.name: LiferayElasticsearchCluster

This is ElasticSearch cluster name, Liferay will use this name later to connect to it.

Also we will need to install two additional plugins. To do it we should run commands in the folder <elastichome>/bin:

# ./plugin install analysis-smartcn
# ./plugin install analysis-kuromoji

(actually this plugins installation tip is missed in official documentation)

OK, everything is ready. We can start ElasticSearch (./elasticsearch command in folder bin). You can check logs in folder logs.

Setup Liferay to work with remote ElasticSearch

Stop portal and create file <liferayhome>/osgi/configs/com.liferay.portal.search.elasticsearch.configuration.ElasticsearchConfiguration.config:

operationMode="REMOTE"
# If running Elasticsearch from a different computer:
#transportAddresses="ip.of.elasticsearch.node:9300"
# Highly recommended for all non-prodcution usage (e.g., practice, tests, diagnostics):
#logExceptionsOnly="false"

In case you install ElasticSearch on same server as Liferay, you do not need to configure anything else. In case you installed ElasticSearch on aother server, you will need to uncomment transportAddresses and put there correct ip address and port.

Restart portal and after starting performing reindex for all data (Control Panel -> Configuration -> Server Administration -> Reindex all search indexes).

After some time you can test it - now, search functionality should work by same way as it worked before with local ElasticSearch.

 

11.12.2017