This blog post is the 21st day of Magento Advent Calendar 2017.

This method will show you how to use Elasticsearch on Magento Open Source 2.1 using the Amazon Elasticsearch Service and Smile ElasticSuite.

To do this integration, we need to:

  • Configure Amazon Elasticsearch service

  • Install and configure Smile ElasticSuite in your Magento Open Source 2.1 instance

Configure Amazon Elasticsearch Service

Using your Amazon Console account, navigate to Elasticsearch Service (Services > Analytics > Elasticsearch Service). Then click on the "Create a new domain" button. 

Amazon Elasticsearch Service

Step 1: Define Domain

Define your Elasticsearch domain which will be a part of your domain endpoint.

Also, specify the version of the Elasticsearch engine that you will be using for your domain. To connect Elasticsearch with Smile ElasticSuite, we should use Elasticsearch 2.1 or higher.

step 1: Define domain

Step 2: Configure Cluster

Configure the instance and storage settings for your cluster based on your requirements.

Choose the correct instance type and instance count depending on your needs. (For testing purposes, we will select t2.small.elasticsearch)

step 2: Configure cluster

Then, select a storage type that is suited for your data nodes.

step 2: Configure cluster

Step 3: Set Up Access

Configure the network by selecting VPC access, this will use private IP addresses from your VPC to provide security by default.

step 3: Set up access

Attach policies to control access to your domain, you can do so by selecting a policy template from the template selector.

step 3: Set up access

Step 4: Review

Review the information, and then choose "Confirm and create" button.

step 4: Review

After successfully creating your Elasticsearch domain, its status will be "Loading" at first.

 step 4: Review

You will need to wait for several minutes for it to be on "Active" status.

 step 4: Review

※ Take note of the VPC endpoint, we will be using it later to connect Elasticsearch with Magento.

Install and Configure Smile ElasticSuite

To install Smile ElasticSuite we need to have the following prerequisites:

  • ElasticSearch 2.1 or higher with "Scripting Enabled" and ICU and Phonetic plugin installed
  • Magento 2.1.x instance

Then we can proceed with the installation of ElasticSuite:

Install ElasticSuite

Install ElasticSuite via composer:

composer require smile/elasticsuite

Enable the module and run ElasticSuite setup:

bin/magento module:enable Smile_ElasticsuiteCore Smile_ElasticsuiteCatalog Smile_ElasticsuiteSwatches Smile_ElasticsuiteCatalogRule Smile_ElasticsuiteVirtualCategory Smile_ElasticsuiteThesaurus Smile_ElasticsuiteCatalogOptimizer Smile_ElasticsuiteTracker
bin/magento setup:upgrade

Add a custom module via app/code with the following content in etc.config file:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <smile_elasticsuite_core_base_settings>
            <es_client>
                <servers>vpc-test-my_server.ap-northeast-1.es.amazonaws.com:443</servers><!-- Use the VPC endpoint that we took down a while ago -->
            </es_client>
        </smile_elasticsuite_core_base_settings>
    </default>
</config>

The custom module should depend on Smile_ElasticsuiteCore to ensure that configuration will be loaded in the right order:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="MyProject_ElasticSuite" setup_version="1.0.0">
        <sequence>
            <module name="Smile_ElasticsuiteCore"/>
        </sequence>
    </module>
</config>

Configure ElasticSearch Server

Configure ElasticSearch server via Stores > Configuration > Smile Elastic Suite > Base Settings.

The VPC endpoint that we have specified in the custom module should appear on the Elasticsearch Servers List. Use HTTPS and for other settings you can leave the default values.

Elasticsearch Client

Process Indexing

Finally, process a full reindexing of the catalogsearch_fulltext index.

bin/magento index:reindex catalogsearch_fulltext
bin/magento index:reindex elasticsuite_categories_fulltext
bin/magento index:reindex elasticsuite_thesaurus

After the reindex is done, you can now view your frontend catalog and search pages being rendered via Smile Elastic Suite. 

Preview

Below is an example of autocomplete feature using ElasticSuite.

※ For other features and customizations, you can check Smile-SA/elasticsuite Github for reference.

Summary

As Elasticsearch service is only available in Magento Commerce Edition, you can benefit from the advantages of using Elasticsearch on your Magento Open Source 2.1.x instance using this method. 

Tomorrow, it will be imrankln's advent calendar blog entry. Yoroshiku Onegaishimasu!