Configure Magento to use Elasticsearch
This section discusses the minimum settings you must choose to test Elasticsearch with Magento 2. For additional details about configuring Elasticsearch, see the Magento Commerce User Guide.
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, click Elasticsearch or Elasticsearch 5.0+ as the following figure shows. (The Elasticsearch 5.0+ option is not available for Magento 2.1.)
-
The following table discusses only the configuration options required to test the connection with Magento.
Unless you changed Elasticsearch server settings, the defaults should work. Skip to the next step.
Option Description Elasticsearch Server Hostname Enter the fully qualified host name or IP address of the machine running Elasticsearch.
Magento Commerce (Cloud): Get this value from your integration system.
Elasticsearch Server Port Enter the Elasticsearch web server proxy port. In our example, the port is
8080
but if you're using a secure proxy, it's typically443
.Magento Commerce (Cloud): Get this value from your integration system.
Elasticsearch Index Prefix Enter the Elasticsearch index prefix. If you use a single Elasticsearch instance for more than one Magento installation (Staging and Production environments), you must specify a unique prefix for each installation. Otherwise, you can use the default prefix magento2
.Enable Elasticsearch HTTP Auth Click Yes only if you enabled authentication for your Elasticsearch server. If so, provide a user name and password in the provided fields. - Click Test Connection.
One of the following displays:
Result | Meaning |
---|---|
Magento successfully connected to the Elasticsearch server. Continue with Configure Apache and Elasticsearch or Configure nginx and Elasticsearch. | |
Try the following:
|
Reindexing catalog search and refreshing the full page cache
After you change Magento’s Elasticsearch configuration, you must reindex the catalog search index and refresh the full page using the Admin or command line.
To refresh the cache using the Admin:
- In the Admin, click System > Cache Management.
- Select the check box next to Page Cache.
- From the Actions list in the upper right, click Refresh.
The following figure shows an example.
To clean the cache using the command line, use the magento cache:clean
command.
To reindex using the command line:
- Log in to your Magento server as, or switch to, the Magento file system owner.
-
Enter any of the following commands:
Enter the following command to reindex the catalog search index only:
php <your Magento install dir>/bin magento indexer:reindex catalogsearch_fulltext
Enter the following command to reindex all indexers:
php <your Magento install dir>/bin magento indexer:reindex
- Wait while the reindexing completes.
Unlike the cache, indexers are updated by a cron job. Make sure cron is enabled before you start using Elasticsearch.