Skip to main content

How to Configure Elasticsearch in Magento 2

The search engine of any e-commerce platform is arguably the essential part of the store. With an efficient search engine, such as Elasticsearch, customers can quickly locate everything they need from your website. This boosts a positive customer experience and leads to an increase in sales.


What is Elasticsearch?

Elasticsearch is an open-source analytics database and search engine. It is fast, efficient, and powerful enough to handle many searches at one time, and works by storing data centrally and mapping it effectively. This enables the location and retrieval of data to be done efficiently and at high speeds. It is even capable of full-text searches on an HTTPS interface.

Why use Elasticsearch in Magento 2?

If you want to boost the efficiency of your e-commerce store, you need a powerful search engine. Powerful search engines help customers go around the store quickly and enables them to reach your products with ease. If you are an existing e-commerce store owner, you will understand that a laggy search engine can frustrate customers and reduce the number of products they open in your store, which leads to low conversion of visitors to your site. With Elasticsearch, you get faster and more efficient searches.

If that’s not enough of a reason, here are the top nine reasons Elasticsearch is great for Magento 2.

1. Reindex

Reindex is the synchronisation of data in Elasticsearch. It is used because data in Elasticsearch is always secondary, and works by rebuilding an index through use of the stored data in the table of the index. In turn, it leads to the replacement of the old copy of the index. For Magento Open Source/Adobe Commerce users, there are two different ways of creating the reindex: (1) full reindex and (2) partial reindex. Partial reindex focuses only on the products that have been changed, whereas full reindex gives the developer freedom to trigger it manually via code.

2. Search Request

A search request is a string of name-value pairs that define the parameters of the search. This allows users to make custom searches of whatever they want within your e-commerce store. All the customer has to do is enter the keywords, and Elasticsearch will do the rest. Requests in Elasticsearch use different query types to achieve fast results. Some include the quick search container, the advanced search container, and the catalogue view container.

3. Category View Page

A category view page allows you to sort the products in your store into groups. This feature will enable customers to filter the products that they want to locate. Thanks to Elasticseach, Magento can quickly get the information of matching products to the query. Here, Magento sends customer requests to Elasticsearch to find products with matching IDs. From the Elasticsearch results, Magento loads the products from the MySQL database, then the products are displayed on the interface for the customer.

4. Quick Search

Quick search is a mechanism used in the category view page that provides accurate and fast results because the data in Elasticsearch is not stored at the front end. With quick search, your store can find products faster and more accurately. Once a product is found, it is loaded directly from the MySQL database. For instance, assume a product named “Torchlight” on MySQL is indexed as “Lamp” in Elasticsearch. If you type in “Torchlight” in the search box, you will not get any results, but when you type “Lamp”, the result that pops up is the “Torchlight” and every other product indexed as Lamp in MySQL.

5. Advanced Search

In as much as there is a quick search feature, an advanced search feature is also necessary. This feature is similar to the quick search feature, but comes with some added search options. Here, the customer can add more search details — such as price, size, color, and more. Advanced search produces a finer, more well-detailed search result, and works perfectly for users who know the specific product they are looking for.

6. Search Suggestions

The Search Suggestions feature helps users to find results better, but does not interfere with the leading search in any way. What it does is offer suggestions to the primary search of the user. This usually happens for a few reasons. One such reason is due to a typographical error by the customer. In this scenario, it Search Suggestions will display a “Did you mean...” suggestion on the search results page, which helps customers realize their mistakes and shows the correct product at the same time. In other scenarios, it happens when there are no results from the query. In this instance, the tool will offer alternatives that are similar to the query and available in the store.

7. Vue Storefront

Vue Storefront is a frontend application that you can easily connect to Magento. It uses Elasticsearch as a NoSQL database because Magento indexes its entities in Elasticsearch. In turn, Vue Storefront can easily reach data without having to make requests from Magento.


Easy Steps to Configure Magento 2 Elasticsearch

Configuring Elasticsearch to work with Magento is relatively easy, however, you should follow the steps below to get the best results.

Step 1: Configure Search Options

As a first step, open the store configuration under “Settings,” then open the catalogue and expand its search section. Here, you can edit the minimum and maximum query length to determine where the store activates Elasticsearch. Next, set up the number of top search results to cache to store a faster response, and set up the indexation speed and the limit of the autocomplete.

Step 2: Configure Magento Elasticsearch Connection

For Step 2, enter the Elasticsearch server hostname and port. The default here is the “localhost.” Enter a prefix for the Elasticsearch index and enable the Elasticsearch HTTP Authentication. The authentication suggests a username and password to allow access to the Elasticsearch server on Magento 2. Edit the server timeout and test the connection to verify your Magento 2 Elasticsearch configuration.

Step 3: Configure Suggestions and Recommendations

This is the final step. When ready, turn on search suggestions and set up the number of suggestions and their results. Next, turn on search recommendations and set up the number of recommendations and their results, then save your configuration.


Key Takeaways

It is clear that Elasticsearch can be a powerful tool that will maximize the user experience for your store. It is fast, efficient, and reliable; however, the best part is that you can implement Elasticsearch fairly easily. with our full-stack web services. You can reach out to us, and our professionals will help you get it all done!