Magento 2 / Server Setup

How to install ElasticSearch for Magento 2 on CentOS/RHEL

by , , revisited on

We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

ElasticSearch and Magento 2

ElasticSearch in Magento 2 is not only about search, as the name implies.
It actually speeds up the display of things throughout Magento, e.g. anywhere you browse the catalog, like category pages.
So, for a supporting Magento version, and, if you have adequate RAM available, installing and using ElasticSearch for Magento 2, is a must.

In this short tutorial, I review simple steps on how to set up ElasticSearch in a single-server scenario, on CentOS/RHEL 7 and CentOS/RHEL 8.

Installing ElasticSearch package

The latest Magento, at the time of this writing, supports only the ElasticSearch 7.x series, so this is what we are going to install.

Magento 2.4 docs recommend specifically 7.9.x as being compatible. To install it, run:

sudo yum -y install
sudo yum -y install elasticsearch

Enable ElasticSearch service by simply running:

sudo systemctl enable --now elasticsearch

Verify it’s running:

curl -XGET 'localhost:9200/_cat/health?v&pretty'

Should yield:

epoch      timestamp cluster       status shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1601396097 16:14:57  elasticsearch yellow          1         1      3   3    0    0        3             0                  -                 50.0%

Configure Elasticsearch within Magento

To configure Magento to use Elasticsearch:

  • Log in to the Magento Admin as an administrator.
  • Click Stores > Settings > Configuration > Catalog > Catalog > Catalog Search.
  • From the Search Engine list, select your Elasticsearch version.

Now, reindex everything:

bin/magento indexer:reindex


If you want to reset ElasticSearch indexes, here’s a handy command:

curl -X DELETE 'http://localhost:9200/_all'

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: