How to install and configure elasticsearch on magento 2

Avatar image of Maarten Maarten
April 20, 2023
Installing and configuring Elasticsearch on Magento 2 involves several steps. Here's a step-by-step guide to help you with the process:

Installing and configuring Elasticsearch on Magento 2 involves several steps. Here’s a step-by-step guide to help you with the process:


Step 1: Install Elasticsearch

First, you need to install Elasticsearch on your server. Here’s how you can do it:

  • Add the Elasticsearch repository to your system:
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
sudo vi /etc/yum.repos.d/elasticsearch.repo
  • Add the following configuration to the file and save it:
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
  • Install Elasticsearch using yum:
sudo yum install elasticsearch


Step 2: Configure Elasticsearch

Once Elasticsearch is installed, you need to configure it by editing the configuration file. Here’s how you can do it:

  • Open the Elasticsearch configuration file:
sudo vi /etc/elasticsearch/elasticsearch.yml
  • Add the following configuration to the file:
cluster.name: magento
node.name: magento
network.host: localhost
http.port: 9200
  • Save and exit the file.
  • Restart Elasticsearch:
sudo systemctl restart elasticsearch


Step 3: Install the Elasticsearch module for Magento

Now that Elasticsearch is installed and configured, you need to install the Elasticsearch module for Magento. Here’s how you can do it:

  • Log in to your Magento 2 server.
  • Change to your Magento root directory:
cd /var/www/html/magento2
  • Install the Elasticsearch module using composer:
composer require magento/module-elasticsearch
  • Run the Magento setup upgrade command:
bin/magento setup:upgrade


Step 4: Configure Magento to use Elasticsearch

Finally, you need to configure Magento to use Elasticsearch as its search engine. Here’s how you can do it:

  1. Log in to your Magento 2 Admin Panel.
  2. Go to Stores > Configuration > Catalog > Catalog > Catalog Search.
  3. Set the following options:
    • Search Engine: Elasticsearch 7.0+
    • Elasticsearch Server Hostname: localhost
    • Elasticsearch Server Port: 9200
  4. Save the configuration and flush the Magento cache:
bin/magento cache:flush

That’s it! Elasticsearch is now installed and configured on your Magento 2 server, and Magento is set up to use it as its search engine.

Industry news straight to your inbox

Get the latest commerce news, trends, and strategies to grow your business
Subscribe to the newsletter
By submitting this form, you agree to receive promotional messages from Magstack. Unsubscribe any time by clicking the link in our emails.
Select location and language

Contact Our Sales Team

Learn more about our products, features, and pricing options.
By submitting this form, you agree to receive promotional messages from Shopify about its products and services. You can unsubscribe at any time by clicking on the link at the bottom of our emails.
Product
Pricing
Use cases
Recourses
Documentation
Log in
Start a free trial