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 versions 1.4, 1.7, 2.4, and 5.2 (requires Magento Commerce v2.2.3 or later). The recommended version is 5.2.

If you are upgrading to Magento Commerce 2.1.3, you must change your configuration to replace Solr with Elasticsearch as discussed in the 2.1.3 Release Notes.

To enable Elasticsearch:

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

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

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

    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.

Add 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:

elasticsearch:
    type: elasticsearch:5.2
    disk: 1024
    configuration:
    plugins:
        - analysis-icu
        - lang-python

The following are supported Elasticsearch plugins for version 2.4:

  • analysis-icu: ICU Analysis Plugin, Support ICU Unicode text analysis
  • analysis-kuromoji: Japanese (kuromoji) Analysis Plugin, Japanese language support
  • analysis-phonetic: Phonetic Analysis Plugin, Phonetic analysis
  • analysis-smartcn: Smart Chinese Analysis Plugins
  • analysis-stempel: Stempel Polish Analysis Plugin
  • cloud-aws: AWS Cloud Plugin, allows storing indices on AWS S3
  • cloud-azure: Azure Cloud Plugin
  • cloud-gce: GCE Cloud Plugin
  • delete-by-query: Support for deleting documents matching a given query
  • discovery-multicast: Ability to form a cluster using TCP/IP multicast messages
  • lang-javascript: JavaScript language plugin, allows the use of JavaScript in Elasticsearch scripts
  • lang-python: Python language plugin, allows the use of Python in Elasticsearch scripts
  • mapper-attachments: Mapper attachments plugin for indexing common file types
  • mapper-murmur3: Murmur3 mapper plugin for computing hashes at index-time
  • mapper-size: Size mapper plugin, enables the _size meta field

Magento does not support the ElasticSuite third-party plugin.

See Elasticsearch plugin documentation.

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 verify information used for configurations and settings:

  1. Use SSH to log in to the remote environment.

  2. Create pretty-print of all relationships for services and configuration data for that environment.

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

The Staging and Production environments share a single Elasticsearch instance; therefore, you must specify a unique Elasticsearch prefix for each environment.