Steps to install and configure elasticsearch with magento

Installation & Configuration of ElasticSearch with Magento

ElasticSearch :

Elasticsearch is a distributed, open source search and analytics engine, designed for horizontal scalability, reliability, and easy management. elasticsearch combines the speed of search with the power of analytics via a sophisticated, developer-friendly query language covering structured, unstructured, and time-series data.

 

Features of elasticSearch :

  • Real-Time Data
  • Real-Time Advanced Analytics
  • Massively Distributed
  • High Availability
  • Multitenancy
  • Full-Text Search
  • Document-Oriented
  • Schema-Free
  • Developer-Friendly, RESTful API
  • Per-Operation Persistence

 

In this tutorial, we will install & configure elasticsearch with magento platform.

The steps provided have currently been tested on: Ubuntu 14.04

ElasticSearch Installation & Configuration Steps

Step 1 : Install Dependency package

whenever we installing any package that time we need to install supportive or dependent package of that applications. Elasticsearch will run with the Java application so you need to first install Java version 1.7 or higher on your server or system.
Follow below commands to install Java.

  • apt-get update
  • apt-get install openjdk-7-jdk
  • Java -version -- > Verfiy Java Version

if you want to install Java 8 on your system or server then first add below repository with command,

  • add-apt-repository -y ppa:webupd8team/java
  • apt-get update
  • apt-get -y install oracle-java8-installer
  • java -version -- > Verify Java Version

Step 2 : Download & install ElasticSearch

Now you need to download elasticsearch on the server. Here I have use elasticsearch version 1.7.5 if you want the latest version of elasticsearch you can download it from https://download.elastic.co/elasticsearch/.

The reason I have installed older version is because of Magento version which we are using is only supporting elasticsearch older than 1.7. Developers face some functionality level issues with the latest version so we are going with the version 1.7.5.

Step 3 : configuration of ElasticSearch

To configure elasticsearch open file 'elasticsearch.yml' which is basically resides under '/etc/elasticsearch' directory. ElasticSearch will not provide internal security and its HTTP API is publicly accessible so first, we need to make our elasticsearch secure.

For securing elasticsearch, you need to block or restrict Elasticsearch HTTP API from outside access using network.bind_host.
The second important thing if you are using elasticsearch locally in your company make sure you set cluster name of elasticsearch otherwise elasticsearch can merge all the data when its run on the same network. The cluster name is a unique name which helps to keep all systems or projects data separate and it will not be merged.
Also, for additional security, you can disable dynamic scripts which are used to evaluate custom expressions. By crafting a custom malicious expression, an attacker might be able to compromise your environment.

vim /etc/elasticsearch/elasticsearch.yml
cluster.name: project-name
network.bind_host: privateip or 127.0.0.1
#To disable custom expressions or dynamic scripts, add the following line is at the end of the file
script.disable_dynamic: true

Save and close file.

Step 4 : Magento level configuration with elasticsearch

I hope you have already installed elasticsearch extension or module on Magento platform if not you will have an elastic extension from https://github.com/jreinke/magento-elasticsearch/tree/master/lib/Elastica and paste it under your codebase in the lib directory.
After enabling module on Magento go to "lib/Elastica/Client.php" file and change the value of DEFAULT_HOST with your local IP or use localhost as per your requirement.
Recommended always run elasticsearch on server private IP.

vim /codebase/lib/Elastica/Client.php

const DEFAULT_HOST = '127.0.0.1 or Private-IP';

Save and close the file.

Step 5 : Increase value in php.ini

Sometimes we have big data for search index and when we reindex data from Magento panel it throws an error like increase max_execution_time or increase memory_limit so you need to increase it to run your indexing without fail.

vim /etc/php5/fpm/php.ini
max_execution_time 3600
memory_limit 512M

Save and close the file.

Step 6 : Restart Service

The final step is to restart your respected service for reflecting changes of elasticsearch configuration files and php.ini values.

  • /etc/init.d/nginx restart && /etc/init.d/php5-fpm restart
  • /etc/init.d/elasticsearch restart OR service elasticsearch restart

Step 7 : Reindex Data

To reindexing data, login to your Magento admin panel and go to "system-->Index Management" then choose "Reindex Data" from drop-down list and select the Search index data and click on submit.

  • http://yourwebsitename.com/admin
Magento Admin Panel
Login To Magento Admin Panel
Magento Index Management
Go to System --> Index Management
magento-3
Tick or Select on Checkbox to Reindex Data & Click Submit Button
Magento Backend
Reindexing Completed Successfully

Step 8 : Test Indexing

Once your reindexing is completed run the below command on the terminal to check the indexing is done properly. it will show you index data which means it works successfully.

index-terminal
Run Command "curl 'localhost:9200/_cat/indices?v'"

That's it Installation and configuration of elasticsearch with Magento are completed.

Check below URL to understand some more commands related to elasticsearch,

If you’re facing any difficulties while configuring ElasticSearch. Please do comment your queries or problem via the comment section, till then stay tuned to techthings.org for more such valuable articles

You can monitor your elasticsearch service with nagios refere below url,

  • Monitor ElasticSearch Service with Nagios

Latest Comments
  1. Nashwan September 22, 2016
  2. olivedev January 11, 2017
    • Prashant Thorat January 26, 2017
  3. Mgento February 15, 2017
    • Prashant Thorat February 21, 2017
  4. Mike March 7, 2017
  5. Mike March 7, 2017

Leave a Reply

Your email address will not be published. Required fields are marked *