Magento 2 Elasticsearch

Magento 2 Elasticsearch tutorial on how to use and configure as the primary search engine.

Elasticsearch Elasticsearch is a search engine based on the Lucene library. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents.”

In translation to Magento 2 it’s a search engine that can be used to provide better results and search speeds.

Setup #

Install #

Configuration #

  1. Log in to the Magento Admin.
  2. Go to Stores > Settings > Configuration
  3. Select Catalog > Catalog.
  4. Opend the Catalog Search tab.
  5. In the select Search Engine list, select the corresponding Elasticsearch version.

With the above in place you will have the following inputs available for specifying:

  • Elasticsearch Server Hostname - hostname or IP address of the machine running Elasticsearch.
  • Elasticsearch Server Port - Elasticsearch web server proxy port.
  • Elasticsearch Index Prefix - Elasticsearch index prefix.
  • Enable Elasticsearch HTTP Auth - Set only if your Elasticsearch server requires authentication.

Indexing #

After the Configuration step you must reindex the catalog search index and the full page cache. This can be done via admin and command line.

Cache refresh admin #

  1. Login into Admin area.
  2. In the Admin, click System > Cache Management.
  3. Click on the checkbox that is next to Page Cache.
  4. From the Actions list on top right, select Refresh.
  5. Click Submit.

Cache refresh Command Line #

To refresh the Full Page Cache after enabling Elasticsearch you can use command bellow:

php bin/magento cache:clean full_page

This will output something like:

Cleaned cache types:

Reindex Command Line #

Reindexing after configuring Elasticsearch can be done only via command-line, the option to reindex via admin has been removed by the Magento team. Bellow will reindex the catalog search index only.

php bin/magento indexer:reindex catalogsearch_fulltext

This will output something like:

Catalog Search index has been rebuilt successfully in 00:00:05

It is important to have Magento 2 Cron configured properly as Magento uses it to keep indexers in sync with main data.

Module #

Need help with Magento 2 Elasticsearch ?