Magento 2.3 Elasticsearch

Magento 2.3 Elasticsearch

Rate this article

Share this article

Read Magento 2.3 elasticsearch 7 for more information.

Magento is an open-source framework used for e-commerce websites. It is quite popular due to the availability of multiple supporting extensions and add-ons to impart an amazing e-commerce experience. One of these extensions is the ElasticSearch. As the name suggests, it is a search extension that allows you to search for a different product from the available catalog. Earlier Magento used the MySQL search engine which was not that great at full-text searching and faced performance issues but with ElasticSearch it is not the case.

Magento 2.3 Elasticsearch

Magento 2.3 Enable Elasticsearch

ElasticSearch uses advanced search technology that supports multiple languages and it also performs well with stops words and synonyms. ElasticSearch uses indexing for searching and the results are fetched based on the last generated indexes until the one present is not updated or regenerated which means there is more reliability.

Magento 2.3 Elasticsearch

ElaticSearch also supports real-time data analysis which can come in handy while working with e-commerce. Along with searching it also provides you with complete reports, analysis, performance reports, storage, and much more. ElasticSearch is very accurate and is scalable on a large scale. 

Magento 2.3.1 adds support for Elasticsearch 6.x, and it is enabled by default. Magento still provides modules for Elasticsearch 2.x and 5.x, but these must be enabled in order to use these versions. Elasticsearch 2.x is still available but strongly discouraged. Versions 2.x and 5.x are End of Life. If you must run Elasticsearch 2.x or 5.x with Magento 2.3.1, you must downgrade the Elasticsearch client to an older version. Follow the instructions in Change the Elasticsearch Client.

How to Configure Elasticsearch in Magento 2

Using Elasticsearch as your catalog search solution provides the following benefits:

  • Quick and advanced searches on products in the catalog
  • Support for multiple languages
  • Support for stop words and synonyms
  • Indexing does not impact customers until the reindex is completed

Elasticsearch returns search results based on the last generated index until the new one has been completely indexed so there is no disruption to customers.

  • Accurate, performant, and scalable
  • Works well out of the box
  • Easy to horizontally scale
  • Supports real-time data and analysis
  • Can be used as a document-oriented datastore
  • Applications in framework beyond search, including reporting, personalization, performance, and storage

Install Elasticsearch 6.x

  1. Log in to your Magento server as a user with root privileges.
  2. CentOS: Install Elasticsearch 6.x using the Elasticsearch RPM documentation
  3. Ubuntu: Install Elasticsearch 6.x using the Elasticsearch Ubuntu documentation
  4. Optionally, configure Elasticsearch as needed. See Configuring Elasticsearch for more information.
  5. If not already running, start Elasticsearch:
    sudo service elasticsearch start
    Verify that Elasticsearch is working by entering the following command on the server on which it is running:
    curl -XGET ‘<host>:9200/_cat/health?v&pretty’

Configure Magento 2 elasticsearch

  1. Log in to the Magento Admin as an administrator.
  2. Click Stores > Settings > Configuration > Catalog > Catalog > Catalog Search.
  3. From the Search Engine list, select your Elasticsearch version.

Magento 2.3 Elasticsearch

  • Make sure the Elasticsearch server is running.
  • If the Elasticsearch server is on a different host from Magento, log in to the Magento server and ping the Elasticsearch host. Resolve network connectivity issues and test the connection again.
  • Examine the command window in which you started Elasticsearch for stack traces and exceptions. You must resolve those before you continue. In particular, make sure you started Elasticsearch as a user with root privileges.
  • Make sure that UNIX firewall and SELinux are both disabled, or set up rules to enable Elasticsearch and Magento to communicate with each other.
  • Verify the value of the Elasticsearch Server Hostname field. Make sure the server is available. You can try the server’s IP address instead.
  • Use the netstat -an | grep **listen-port** command to verify that the port specified in the Elasticsearch Server Port field is not being used by another process.

TO REFRESH THE CACHE USING THE ADMIN:

  1. In the Admin, click System > Cache Management.
  2. Select the checkbox next to Page Cache.
  3. From the Actions list in the upper right, click Refresh.Magento 2.3 Elasticsearch
  4. To clean the cache using the command line, use the magento cache:clean command.

YouTube video

Magento 2 Elasticsearch no results

Magento 2.3.1 adds support for Elasticsearch 6.x, and it is enabled by default. Magento still provides modules for Elasticsearch 2.x and 5.x, but these must be enabled in order to use these versions. Elasticsearch 2.x is still available but strongly discouraged. 

Configure Elasticsearch within Magento

To configure Magento to use Elasticsearch:

  1. Log in to the Magento Admin as an administrator.
  2. Click Stores > Settings > Configuration > Catalog > Catalog > Catalog Search.
  3. From the Search Engine list, select the correct Elasticsearch version as the following figure shows. (The Elasticsearch 5.0+/6.0+ options are not available for Magento 2.1.)

The following table lists the required configuration options to configure and 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 hostname 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 are using a secure proxy, it is typically 443. 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 username and password in the provided fields.
  1. Click Test Connection.

You will see either:

Magento 2.3 Elasticsearch

Continue with:

or you will see:

Magento 2.3 Elasticsearch

If so, try the following:

  • Make sure the Elasticsearch server is running.
  • If the Elasticsearch server is on a different host from Magento, log in to the Magento server and ping the Elasticsearch host. Resolve network connectivity issues and test the connection again.
  • Examine the command window in which you started Elasticsearch for stack traces and exceptions. You must resolve those before you continue. In particular, make sure you started Elasticsearch as a user with root privileges.
  • Make sure that UNIX firewall and SELinux are both disabled, or set up rules to enable Elasticsearch and Magento to communicate with each other.
  • Verify the value of the Elasticsearch Server Hostname field. Make sure the server is available. You can try the server’s IP address instead.
  • Use the command netstat -an | grep **listen-port** to verify that the port specified in the Elasticsearch Server Port field is not being used by another process.

For example, to see if Elasticsearch is running on its default port, use the following command:

netstat -an | grep 9200

If Elasticsearch is running on port 9200, it displays similar to the following: tcp 0 0 :::9200 :::* LISTEN

After you change Magento’s Elasticsearch configuration, you must reindex the catalog search index and refresh the full page cache using the Admin or command line.

To reindex using the command line:

  1. Log in to your Magento server as, or switch to, the Magento file system owner.
  2. Enter any of the following commands:

Enter the following command to reindex the catalog search index only:

bin/magento indexer:reindex catalogsearch_fulltext

Enter the following command to reindex all indexers:

bin/magento indexer:reindex
Wait until reindexing completes.

Magento 2.3 Elasticsearch list indexes

There was one big announcement made during the Magento Imagine. The announcement stated that ElasticSearch support would be moved to Magento’s open-source version for the 2.3.0 release. 

Magento 2.3 Elasticsearch

Magento 2.3 Elasticsearch                                      

It is good that the release of Magento 2.3 has brought a new update. And that is its integration with ElasticSearch. Here, it is also important to know that indexing doesn’t have much effect on the customers until reindex is done.

 

Many of you may already know that ElasticSearch is a very powerful search engine. It increases the performance of the searches being done. Along with this, ElasticSearch also reduces the displayed list size.

Magento 2.3 Elasticsearch                        

From the search engine list, you can select the right ElasticSearch version and then enter the ElasticSearch index prefix. This will help you to identify the Magento 2.3 ElasticSearch list indexes. So, now is the time to update your store with Magento 2.3.

 

Magento 2.3 Elasticsearch wildcard query

Magento uses ElasticSearch which is really powerful and works with great accuracy. There are multiple search options available in ElasticSearch like simple search and wildcard search. All of these searches proceed on a dedicated server to provide optimal performance with great search result.

Magento 2.3 Elasticsearch

The wildcard search is a type of search where the customer is allowed to enter a part of the name of the product he or she is searching for and the unknown part is to be kept as asterisks (*). Magento 2.3 elasticsearch wildcard query will help in bringing out more appropriate results even when you are not sure about the product name.

magento 2 elasticsearch wildcard type

With ElasticSearch, you get to use four different modes of a wildcard search.

  1. Enabled – In this mode the search is made fully enabled to provide the best result for wildcard searches.
  2. Enabled at the end – In this mode, the search is made on the basis of the first part of the keyword provided by the customer.
  3. Enables at the start – In this mode, the search is made on the basis of the last part of the keyword.
  4. Disabled – If this mode is selected, the customers will not be allowed to search on the basis of a wildcard.

Magento 2 Elasticsearch vs Solr

Solr and Elastic search are both search engines that are widely used.  Here is a detailed comparison of the total cost of ownership, features, and performance of Magento 2 Elasticsearch vs Solr.

Magento 2.3 Elasticsearch

Solr and Elastic search are basically sisters to be honest – both are pretty similar, with Solr being the older one.  They are layers built on top of the core search library Lucene.

Is it an important decision in the first place?  Can I easily slide between them later?  It is an important decision and it is not easy to replace one with another.  As you will shortly see, it is not that one is superior to the other, each of them has proven to be better at a particular problem than the other.  Hence understanding your specific need is more important to make the right choice.  Since it is a choice you make mostly once, I would recommend you spend quality time analyzing your use case.

Do you care more about ease of setup or the capability to tweak the relevance?  If you are for ease of setup, go with Elastic Search.  It is much faster to set up and it would give you a decent start.

If you are an advanced player who would want to be in full control of the search ranking (or relevance), then you have to pick up Solr.  Not that it will give any better results than Elastic Search out of the box, but it would give you more control to create what you are looking for when it comes to ranking.

If you want to search for eCommerce products, documents like pdf, websites, etc, or any other search like music, that is client-facing, you are better off picking up Solr.  You will spend some time setting it up, but you will not be later stuck with a search you cannot improve to full potential.

But when it comes to setting up a search for a Magento store, even considering Magento 2 Elasticsearch vs Solr is overkill. It is recommended that you go with a custom search extension to keep the development cost at a minimum.

You can read more about Solr vs Elasticsearch here.

Magento 2 Elasticsearch Alternative

Elasticsearch is not quite a readymade solution. Building a search interface from Elasticsearch can be challenging. Hence it is not advisable to plunge into the solution. It takes expertise to successfully scale an Elasticsearch cluster and ensure that it functions seamlessly.

Being a CMS Magento has a ton of plugins that can add functionality to your store. On Magento 2,  all that you need to do is install the ExpertRec site search extension from the marketplace. This will automatically replace your default search and add a Magento 2 Custom Advanced Search bar that has facets inbuilt. You can do further customization in the Expertrec Dashboard that comes along with the plugin. This will add a more powerful and customizable search engine to your website. This Magento 2 Advanced Search extension is developed with the Ajax function. It combines all advanced techniques for searching online. The search result will be shown as a drop-down list after starting typing only the first letter of the keywords in the search box.

Cons:

  • It is paid, unlike elastic search.
  • It is hosted on the cloud, and you cannot use it if you have sensitive data to search (same with google custom search).

Pros:

  1. Quick integration, you can get a working search in 5 minutes.
  2. It is a turn-key solution, so you don’t need any developer bandwidth to use this.
  3. It supports multiple file types like pdf, word, etc.

Add Search to your Website

    Are you showing the right products, to the right shoppers, at the right time? Contact us to know more.
    You may also like