How to Configure Magento 2 Elasticsearch

How to Configure Magento 2 Elasticsearch

The Magento 2 Elasticsearch configuration serves as a scalable catalog search solution. It enhances the user experience while improving search performance. It also enhances the overall shopping experience for users. This tutorial covers the installation, configuration, and optimization of Elasticsearch for your Magento 2 store. It will help you enhance your Magento product visibility and boost sales effectively.


Key Takeaways

  • Gain an understanding of what Magento 2 Elasticsearch is and how it operates within your Magento.

  • Discover the prerequisites before setting up Elasticsearch for Magento versions.

  • Explore the process of installing Magento and utilizing Elasticsearch to attain quicker and more precise search results for your store.

  • Check the benefits of utilizing Elasticsearch for enhanced performance in Magento.

  • Learn how Elasticsearch in Magento can reduce cart abandonment.

  • Elasticsearch enhances the overall user experience by offering faster and more relevant search outcomes.

What is Magento 2 Elasticsearch?

Elasticsearch is an open and distributed search and analytics engine. It covers various data types, including textual, numerical, geospatial, structured, and unstructured. Powered by Apache Lucene, an open-source full-text search library, it functions as a full-text search solution. It offers related keywords and complete queries based on the input.


Elasticsearch also enables store-wide search capabilities. It includes suggesting related products, images, prices, ratings, etc, to refine search results.


Starting with Magento 2.4 version, Elasticsearch is the default catalog search engine in Adobe Commerce. It's essential to Magento installations and can be disabled if needed. It significantly improves the customer experience by providing faster and more relevant search results. It also enhances the conversion rate with seamless shopping experiences.

How does Elasticsearch work?

Elasticsearch uses its indexing feature to provide fast and reliable search results. These indices are like organized collections of documents. It makes it easier to retrieve data quickly and store related documents together.


When Elasticsearch receives raw data from various sources, such as logs, system metrics, and web applications, it processes and indexes it. The indexing allows users to perform detailed searches on the data. It also helps them get detailed summaries of their information through aggregations.

Benefits of Elasticsearch For Your Magento Store

1. Enhanced Search Capabilities

Enhanced search plays a crucial role in minimizing bounce rates. Elasticsearch facilitates swift result generation and real-time relevant outcomes. Features like auto-completion and auto-suggestion save customers time and effort while reducing incorrect queries.

Elasticsearch efficiently handles typographical errors or misspellings, a common issue for search engines. It detects stop words and their corresponding phrases, ensuring the provision of accurate and related search results.

2. Quick Search

Elasticsearch is a powerful tool capable of retrieving searched keywords in under 10 seconds. It is significantly faster than traditional SQL-based searches. It uses Lucene and distributed inverted indices for a full-text search.

Elasticsearch speeds up future searches by storing search queries in a cache. It uses cached filters to do this, shortening the time it takes for a document to become searchable. The tool makes Magento search results faster and more responsive.

3. Scalability and Data Management

Elasticsearch is designed with a distributed structure. It stores documents across different parts called "shards.” It adds redundancy in case hardware fails. This setup lets it scale easily to many servers and handle large amounts of data efficiently.

It can work smoothly across different clusters or systems with many nodes. When moving from a smaller cluster to a larger one, minimal preparation is required, making the transition nearly seamless.

4. Data handling

Elasticsearch relies on JSON (JavaScript Object Notation) for its data handling. It stores data in JSON documents, allowing it to understand the data structure and perform searches. This approach means you don't need to define the data structure in advance.

Elasticsearch usually uses default settings for indexing unless you specify a specific data type. If you index an object with a new property later, Elasticsearch updates its mapping definitions automatically. This adaptability eliminates the need for predefined schemas.

Prerequisites to Set Up Elasticsearch In Magento 2.4

As a required add-on to the Magento platform, Elasticsearch must be installed and configured before users upgrade to version 2.4.x.

Note: Adobe no longer supports Adobe Commerce 2.3.x and PHP 7.3. Upgrade to Adobe Commerce 2.4.x and PHP 7.4.x to preserve PCI compliance.

The installation process for Magento 2.4.x now mandates the installation of Elasticsearch, along with these additional prerequisites:

Note: Magento requires Elasticsearch version 7.6.x for all installations.

Install and Configure Magento 2 Elasticsearch via the Admin Panel

Step 1: Configure Search Options

  1. Access Stores from the Magento Admin Panel sidebar and select Configuration under Settings.

  2. Within the Catalog section, click on Catalog > Catalog Search.

Admin panel displaying Magento 2 Elasticsearch search configuration settings

  1. Clear the Use system value checkbox in the Search Engine field and choose the Elasticsearch version installed on your server:
  • Elasticsearch 5.0+ (Deprecated)
  • Elasticsearch 6.x (Deprecated)
  • Elasticsearch 7
  1. Enable or disable the Product EAV indexer by selecting Yes or No in the Enable EAV Indexer field. It enhances indexation speed and prevents third-party extensions from using the indexer.

  2. Set the Minimal and Maximum Query Length to restrict search query text length and word count.

Note- Ensure compatibility with your Elasticsearch search engine configurations.

  1. Enter a number for the Number of top search results to cache field, to speed up responses.

  2. Set a value for Autocomplete Limit to control the maximum number of search results displayed during search autocomplete. It improves search performance and reduces displayed list size. The default number is 8.

Step 2: Configure the Elasticsearch Connection

  1. Input the Elasticsearch Server Hostname. By default, this is set as localhost.

Admin panel showing connection settings for Magento 2 Elasticsearch

  1. Specify the Elasticsearch Server Port.

  2. Define a prefix in the Elasticsearch Index Prefix field to identify the Elasticsearch index. For example, Magento2.

  3. Enable HTTP authentication for Elasticsearch by choosing Yes in the Enable Elasticsearch HTTP Auth field.

  4. Next, enter your designated HTTP username and password.

  5. Set the timeout duration in seconds for the connection in the Elasticsearch Server Timeout field. The default duration is 15 seconds.

  6. To validate the configuration, click on the Test Connection button.

Step 3: Configure Suggestions and Recommendations

  1. In the Enable Search Suggestions field, choose Yes to enable search suggestions.

  2. Specify the number of search suggestions in the Search Suggestions Count section. The default number is 5.

Configuration options for suggestions and recommendations in Magento 2 Elasticsearch

  1. In the Show Results Count for Each Recommendation field, select Yes to show the number of results for each suggestion.

  2. In Enable Search Recommendations, choose Yes to provide recommendations.

Note: Enabling this feature may affect your site's speed.

  1. In Search Suggestions Count, set the number of recommendations you want to offer. The default is 2.

  2. For Show Results Count for Each Recommendation field, select Yes to display the number of results found for each recommendation.

  3. In Minimum Terms to Match, input the minimum terms required for a match.

  4. After configuring your settings, click the Save Config button to save your changes.

Step 4: Reindex Catalog Search and Refresh the Full Page Cache

1. Using the Admin Panel:

  1. In the Admin, go to System > Tools > Cache Management.

  2. Check the box next to Cache Type.

  3. From the Actions list in the upper left corner, choose Refresh.

  4. To clean the cache, click the Flush Magento Cache button in the top-left.

Step-by-step procedure for reindexing and cache refresh in Magento 2 Elasticsearch

  1. Once done, you will see “The Magento cache storage has been flushed.

2. Using the Command Line:

  1. Log in as the file system owner or switch to it on your Magento server.

  2. To reindex the catalog search index, run the following command:

bin/magento indexer:reindex catalogsearch_fulltext
  1. To reindex all indexers, run:
bin/magento indexer:reindex
  1. Allow time for the reindexing process to finish. It ensures that your changes take effect and your search functionality remains up-to-date.

FAQs

1. How can I install Elasticsearch in Magento 2?

To install Elasticsearch in Magento 2:

  1. Access the Admin Panel.

  2. Navigate to Stores> Configuration > Catalog > Catalog Search.

  3. From there, you can configure Elasticsearch settings, including the server hostname, port, and authentication details.

Follow the outlined steps for setting up and testing the Elasticsearch connection.


2. What are the available Magento 2 Elasticsearch extensions for Magento configuration?

Many third-party extensions can seamlessly integrate Elasticsearch into Magento stores. These extensions facilitate seamless integration. It also enhances the powerful search capabilities of Elasticsearch within the Magento 2 platform.


3. How does Elasticsearch configuration benefit Magento for ecommerce stores?

Elasticsearch configuration within Magento contributes to a great shopping experience. It significantly improves response times and suggests related keywords while showing complete queries. This improvement assists customers in finding products more quickly and reduces cart abandonment rates. It also provides real-time search results.


4. Can Elasticsearch be used to improve response times in Magento 2?

Yes, Elasticsearch comes as the default catalog search engine in the latest version of Magento. Its powerful search engine architecture and caching mechanisms significantly enhance response times. It offers faster and more accurate search results.


5. How does Elasticsearch handle the number of popular search results in Magento 2?

Elasticsearch effectively manages the volume of popular search results in Magento 2. It leverages Apache’s indexing and caching mechanisms. This system speeds up the retrieval of popular search results and stores the search results in the cache for faster response times.


6. What happens to Magento 2 versions that have reached their end of life regarding Elasticsearch integration?

With Magento versions, it's crucial to upgrade to the latest version compatible with Elasticsearch for optimal performance. The latest versions of Magento come integrated with Elasticsearch, ensuring continued support and compatibility.

Summary

Magento 2 Elasticsearch configuration provides a fast and relevant search experience for your online store. It helps you boost search weights, enable multi-store support, and improve overall search performance. This tutorial covered the installation, configuration, and advantages of utilizing Elasticsearch in Magento 2. It also provided insights into leveraging this potent search engine for optimal performance.


You can optimize your Magento server hosting to complement the Elasticsearch setup and maximize the efficiency of your online store.

Maria Ajnawala
Maria Ajnawala
Technical Writer

Maria has over five years of expertise in content marketing, specialising in Magento insights and industry trends. She excels in creating engaging content that resonates within the Magento community.


Get the fastest Magento Hosting! Get Started