Set up Elasticsearch service

Elasticsearch is an open source product that enables you to take data from any source, any format, and search and visualize it in real time.

  • Elasticsearch performs quick and advanced searches on products in the product catalog
  • Elasticsearch Analyzers support multiple languages
  • Supports stop words and synonyms
  • Indexing does not impact customers until the reindex operation completes

Magento Commerce supports Elasticsearch version 5.2 and 6.x (supported by Magento version 2.3.1 and later).

To enable Elasticsearch:

  1. Add the elasticsearch service to the .magento/services.yaml file with the Elasticsearch version and allocated disk space in MB.

    1
    2
    3
    
    elasticsearch:
        type: elasticsearch:6.5
        disk: 1024
    
  2. Set the relationships property in the .magento.app.yaml file.

    1
    2
    
    relationships:
        elasticsearch: "elasticsearch:elasticsearch"
    
  3. Add, commit, and push code changes.

    1
    
    git add -A && git commit -m "Enable Elasticsearch" && git push origin <branch name>
    

    For information on how these changes affect your environments, see Services.

  4. Verify the relationships and configure Elasticsearch in the Admin UI.

Elasticsearch plugins

Optionally, you can add plugins with the .magento/services.yaml file. For example, to enable the ICU analysis plugin and Python script support plugin, add the configuration:plugins section with the listed plugin codes:

1
2
3
4
5
6
7
elasticsearch:
    type: elasticsearch:6.5
    disk: 1024
    configuration:
        plugins:
            - analysis-icu
            - lang-python

See Elasticsearch plugin documentation.

If you use the ElasticSuite third-party plugin, you must update the ece-tools package to version 2002.0.19 or later.

Verify relationships

Magento Commerce Cloud uses the MAGENTO_CLOUD_RELATIONSHIPS variable to retrieve the environment-related relationships. You must use this information when you configure Elasticsearch through the Magento Admin.

To print the connection information for Elasticsearch:

1
php -r 'print_r(json_decode(base64_decode($_ENV["MAGENTO_CLOUD_RELATIONSHIPS"])));'

The response includes all relationships for services and configuration data for that environment; the Elasticsearch information is similar to the following:

1
2
3
4
5
6
7
8
"elasticsearch" : [
      {
         "host" : "elasticsearch.internal",
         "ip" : "250.0.97.96",
         "scheme" : "http",
         "port" : "9200"
      }
   ],

Staging and Production environments that are in the same cluster share a single Elasticsearch instance, so you must specify a unique Elasticsearch prefix for each of these environments.