This article is a detailed guide to enabling Elasticsearch on Magento Commerce (Cloud).
Step 1: Activate on Integration; request on Staging and Production
1.1: Activate on Integration environment
Make changes in .magento/services.yaml and .magento.app.yaml configuration files on your local development environment. Later, you will git push the changed files to your Integration environment to enable Elasticsearch there.
This step is covered on DevDocs, see Add Elasticsearch in services.yaml and .magento.app.yaml.
.magento/services.yaml
Add the Elasticsearch section:
elasticsearch:
type: elasticsearch:1.7
disk: 1024
where type
includes the version to be installed and disk
specifies the allocated disc space (in MB).
If you used the Solr search before, delete the Solr section to avoid memory leaks:
solr: type: solr:4.10 disk: 1024
.magento.app.yaml
In the relationships
section, add the elasticsearch line:
elasticsearch: "elasticsearch:elasticsearch"
If you used the Solr search before, delete the Solr line to avoid memory leaks:
solr: "solr:solr"
After changes, the relationships
section might look like this:
relationships: database: "mysql:mysql" redis: "redis:redis" elasticsearch: "elasticsearch:elasticsearch"
1.2: Request activation on Staging and Production
Submit a Support Ticket requesting to activate Elasticsearch on your Staging and Production environments.
In your ticket, please specify the Elasticsearch version you want to activate. Magento Commerce (Cloud) supports versions 1.4, 1.7, and 2.4; default version is 1.7.
Step 2: Push changes to Integration
To enable Elasticsearch on the Integration environment, add the changed YAML files to git and push changes to the server:
git add -A git commit -m "Switching solr for elaticsearch" git push <name_of_remote_repo> <name_of_remote_branch>
For Staging and Production, pushing the changed YAML files does not trigger the activation. Elasticsearch is only enabled once your Support Ticket (the one that requests the activation) is processed.
Step 3: Configure Magento to use Elasticsearch
You must perform this step for any environment (Integration, Staging, Production) to get Elasticsearch working.
For Staging and Production environments, this configuration step is only available after your Support Ticket for activating Elasticsearch has been processed successfully and Elasticsearch has been activated.
For Magento Commerce (Cloud) 2.2.0 (and later) with the Configuration Management functionality, the Elasticsearch configuration settings (applied on the Integration environment) are stored and applied automatically once you trigger the deployment procedure on Staging and Production environments. Read more about the Configuration Management on DevDocs (2.1; 2.2; Pipeline Deployment) and Knowledge Base (Reduce deployment downtime with Configuration Management in Magento Commerce (Cloud)).
3.1: SSH into your environment
See SSH to an environment on DevDocs.
3.2: Verify environment-related relationships
Execute the following command:
- echo $MAGENTO_CLOUD_RELATIONSHIPS | base64 -d | json_pp
The response includes relationships for services and configuration data for the environment. In the response, you will find the data similar to these Elasticsearch settings:
"elasticsearch" : [
{
"host" : "elasticsearch.internal",
"ip" : "250.0.97.96",
"scheme" : "http",
"port" : "9200"
}
],
3.3: Enable and configure Elasticsearch via Magento Admin
These steps are covered with many details in the Configure Magento to use Elasticsearch topic on DevDocs.
- Log in to Magento Admin.
- Navigate to Stores > Configuration > Catalog > Catalog > Catalog Search.
- Select Elasticsearch in the Search Engine menu.
- Specify the Elasticsearch settings obtained in Step 2.2 (above), for example:
- Elasticsearch Server Hostname: elasticsearch.internal
- Elasticsearch Server Port: 9200
- Click the Test Connection button.
If the test passes, the button changes to Successful! Test again? In connection fails, see Step 5 of the Configure Magento to use Elasticsearch topic on DevDocs. - Click the Save Config button.
Specify different Elasticsearch Index Prefixes for Staging and Production
Using the same Elasticsearch Index Prefix for both Staging and Production environments may cause errors, so make sure to specify different prefixes for these environments.