Install and configure Elasticsearch
- Overview of Elasticsearch
- Install prerequisites and Elasticsearch
- Additional resources
- Configure nginx and Elasticsearch
- Configure Apache and Elasticsearch
- Configure Elasticsearch stopwords
Overview of Elasticsearch
In Magento 2.1 for the first time, you can use Elasticsearch for searching your catalog.
- Elasticsearch performs quick and advanced searches on products in the catalog
- Elasticsearch analyzers support multiple languages
- Supports stop words and synonyms
Indexing does not impact customers until reindex is completed
Elasticsearch returns search results based on the last generated index until the new one has been completely indexed so there’s no disruption to customers
- Accurate, performant, scalable
- Works well out of the box
- Easy to horizontally scale
- Supports real-time data and analysis
- Can be used as a document-oriented data store
- Applications in framework beyond search—reporting, personalization, performance, and storage
Magento Enterprise Edition (EE) version 2.1.x supports the following Elasticsearch versions:
- If you get the Elasticsearch software from the Elasticsearch Linux repository, we support versions 2.x.
- If you get the Elasticsearch software from their Elasticsearch-PHP repository, we support the
We also support version 1.7 but recommend you use a later version.
The following figure shows our recommended configuration. All of the tasks we discuss assume you’ve configured your system this way.
The preceding diagram shows:
The Magento application and Elasticsearch are installed on different hosts.
Running on separate hosts is secure, enables Elasticsearch to be scaled, and is necessary for proxying to work. (Clustering Elasticsearch is beyond the scope of this guide but you can find more information in the Elasticsearch documentation.)
Each host has its own web server; the web servers don’t have to be the same.
For example, the Magento application can run Apache and Elasticsearch can run nginx.
Both web servers use Transport Layer Security (TLS).
Setting up TLS is beyond the scope of our documentation.
Search requests are processed as follows:
A search request from a user is received by the Magento web server, which forwards it to the Elasticsearch server.
You configure Elasticsearch in the Magento Admin to connect to the proxy’s host and port. We recommend the web server’s SSL port (by default, 443).
- The Elasticsearch web server (listening on port 443) proxies the request to the Elasticsearch server (by default, it listens on port 9200).
Access to Elasticsearch is further protected by HTTP Basic authentication.
For any request to reach Elasticsearch, it must travel over SSL and provide a valid user name and password.
- Elasticsearch processes the search request.
- Communication returns along the same route, with the Elasticsearch web server acting as a secure reverse proxy.
Install prerequisites and Elasticsearch
The tasks discussed in this section require the following:
Firewall and SELinux
By default, UNIX systems generally enable a firewall with restrictive rules and also enable SELinux, which imposes other types of security on the operating system. It’s easier to run the search engine server in development by disabling the firewall and SELinux but that choice is up to you.
If you choose to enable your firewall and SELinux, you must set up rules to allow TCP traffic between Magento and your search engine’s listen port.
Disable iptables and SELinux
To stop the
iptables (firewall) service, enter the following command as a user with
service iptables stop
To set SELinux for permissive mode:
To determine if SELinux is enabled, enter the following command:
Enforcingdisplays to confirm that SELinux is running. (If
Permissivedisplays, continue with the next section.)
To change to permissive mode, enter:
Set up rules for iptables and SELinux
To set up rules to allow communication with the firewall or SELinux enabled, consult the following resources:
- iptables how-to
- How to edit iptables rules (fedora project)
- 25 Most Frequently Used Linux IPTables Rules Examples
- Introduction to SELinux (CentOS.org)
- SELinux How-To Wiki (CentOS.org)
Install the Java Software Development Kit (JDK)
To determine if Java is already installed, enter the following command:
If the message
java: command not found displays, you must install the Java SDK as discussed in the next section.
See one of the following sections:
Install the JDK on CentOS
Be sure to install the JDK and not the JRE.
yum -y install java-1.7.0-openjdk
Java version 7 might not be available for all operating systems. For example, you can search the list of available packages for Ubuntu.
Install the JDK on Ubuntu
To install JDK 1.8 on Ubuntu, enter the following commands as a user with
add-apt-repository -y ppa:webupd8team/java apt-get -y update apt-get install -y oracle-java8-installer
For other options, see Oracle documentation.
This section discusses how to install the latest 2.x version of Elasticsearch from their repository.
To install Elasticsearch:
- Log in to your Magento server as a user with
CentOS: Enter the following commands in the order shown:
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch vim /etc/yum.repos.d/Elasticsearch.repo
Add the following:
[elasticsearch-2.x] name=Elasticsearch repository for 2.x packages baseurl=http://packages.elastic.co/elasticsearch/2.x/centos gpgcheck=1 gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch enabled=1
Enter the following commands:
yum -y install elasticsearch chkconfig --add elasticsearch
Ubuntu: Enter the following commands in the order shown:
Find the latest 2.x version of Elasticsearch.
Install the latest 2.x version using Elasticsearch documentation
For example, to install Elasticsearch version 2.4.4, enter the following commands in the order shown:
curl -L -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.4.4/elasticsearch-2.4.4.tar.gz tar -xvf elasticsearch-2.4.4.tar.gz cd elasticsearch-2.4.4/bin ./elasticsearch
Open the Elasticsearch configuration file,
elasticsearch.yml, in a text editor.
For example, it might be located in
Add the following parameter to the
Very large catalogs (40,000 SKUs or more)
Catalogs with less than 40,000 SKUs:
For more information, see Setting the BooleanQuery maxClauseCount in Elasticsearch.
- Save your changes to
elasticsearch.ymland exit the text editor.
- Optionally configure the Elasticsearch service.
service elasticsearch start
Verify that Elasticsearch is working by entering the following command on the server on which it’s running:
curl -i http://127.0.0.1:9200/_cluster/health
Messages similar to the following display if Elasticsearch is running:
For additional information, see Elasticsearch documentation