What is ElasticSearch?
ElasticSearch is an open source, a search engine built on Apache Lucene. It provides simple REST-based APIs, distributed systems and uses schema-free JSON documents.
When we need to search a large amount of data for the best match with a specific search, elasticsearch is more preferable than SQL data. We can also get more relevant data using scoring in elastic search. This property separates elasticsearch from other databases.
Which version of Liferay supports ElasticSearch?
Lucene search engine has been replaced with elasticsearch in liferay DXP. Liferay 7.1 only supports ElasticSearch 6.1 or higher. For liferay portal applications, we can handle the document index with minor changes in the service layer. Whenever an entry is added, updated, or deleted, the corresponding document will also be updated or deleted.
By default, elasticsearch runs as an embedded search engine in Liferay. In embedded mode, elasticsearch runs under the same JVM and it’s simple for starting, but running both servers in the same process has drawbacks:
- We have to use the same JVM options for elasticsearch as the Liferay portal.
- Liferay portal and elasticsearch compete for hardware resources.
How to configure ElasticSearch?
Let’s look at the steps given below on how to configure elastic search as a separate server in the Liferay portal.
Step 1: Get version of elasticsearch
While the liferay portal is running on a local machine, we can get details of embedded Elasticsearch by hitting http://localhost:9200 in the browser. You will get JSON data which looks similar to below. Here, “number” field represents version of elasticsearch. You can also get version from Liferay control panel by navigating to Control Panel -> Configuration -> Search.
{ "name" : "UoANDiD", "cluster_name" : "liferay", "cluster_uuid" : "pjMyb3zBRiWnkE48v1RcUw", "version" : { "number" : "6.1.3", "build_hash" : "af51318", "build_date" : "2018-01-26T18:22:55.523Z", "build_snapshot" : false, "lucene_version" : "7.1.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" }
Step 2: Install Elasticsearch
1. Download ZIP file of Elasticsearch from https://www.elastic.co/downloads/past-releases/.
2. Install Elasticsearch by extracting an archive at the desired location in the file system.
3. We can install plugins in elasticsearch using the following syntax.
Syntax: plugin install [plugin-name]
Navigate to [Elastic search home]/bin/ and install the following plugins. Here, plugin executable was renamed to elasticsearch-plugin in elasticsearch 6. Syntax for installing plugins to elasticsearch 6 or above:
Syntax: elasticsearch-plugin install [plugin-name]
Plugins:
- analysis-icu
- analysis-kuromoji
- analysis-smartcn
- analysis-stempel
Step 3: Configure Elasticsearch
Elasticsearch’s configuration file is written in YAML and kept in [Elasticsearch home]/config folder. YAML is a human friendly data serialization standard for all programming languages.
- elasticsearch.yml is for configuring Elasticsearch cluster
- logging.yml is for configuring Elasticsearch logging
Following are some common properties to configure elasticsearch cluster using elasticsearch.yml file.
- cluster.name_LiferayElasticsearchCluster : LiferayElasticsearchCluster is the default name of cluster in liferay portal. You can give any name to the cluster though.
- path.data:/path/to/data : We can set path where to store data
- path.logs: /path/to/logs
- network.host: [bind address]
- http.port: [custom port for http]
Start elasticsearch by navigating to [Elasticsearch home]/bin and run elasticsearch executable.
Step 4: Configure Liferay portal to use elasticsearch cluster
In liferay 7.1, Liferay connector to elasticsearch 6 is already installed. Following are the steps to configure elasticsearch in liferay portal:
1. Go to Control panel -> Configuration -> System settings -> Search -> Elasticsearch
2. Give cluster name of elasticsearch and change operation mode to remote to operate elasticsearch as standalone.
3. Update configuration
4. Restart the server
Step 5: Reindex all search indexes
1. Login as administrator
2. Click on Control panel -> Configuration -> Search
3. Click on execute button of Reindex all search indexes
Conclusion:
Elastic search has always been the talk of the industry as it has been around since 2010 and has become the go to option for developers. Liferay provides elasticsearch as an out-of-box functionality. Hence, we can easily use it.
At AIMDek Technologies, our objective in migration projects is to maintain business continuity and coexistence with existing applications. Our Liferay Migration experts help strengthen business transformation with Liferay Portal Migration and Upgrade Services. We not only migrate your servers and files from obsolete systems but also migrate your images, blogs, content, cached files and data securely. Talk to our experts to learn more about our Liferay Consulting Services here.