logo company

Contact us:
+(48) 572 970 235 or Book a call
Guides Magento Optimization Ecommerce Integration

How to Configure Elasticsearch in Magento 2: Step-by-Step Setup

0%
How to Configure Elasticsearch in Magento 2: Step-by-Step Setup

A staggering 53% of mobile shoppers will abandon a site if it takes longer than 3 seconds to load. For Magento 2 store owners, the platform's default search can struggle with large catalogs, often delivering slow and inaccurate results that frustrate customers.

This article provides a clear, step-by-step guide to configuring Elasticsearch, the high-performance search engine, to solve this problem by ensuring fast, typo-tolerant, and relevant product discovery on your e-commerce platform.

What is Magento 2 Elasticsearch?

Think of Elasticsearch as the intelligent search engine powering the modern Magento 2 store. It's a high-performance, open-source technology that replaced the platform's basic MySQL search, transforming a simple query box into a fast, intuitive, and powerful product discovery tool.

Unlike a standard database lookup, Elasticsearch provides:

  • Blazing Speed: Delivers search results in milliseconds, even for large catalogs.

  • Relevant Results: Uses smart algorithms to rank products by true relevance, not just basic matches.

  • Typo Tolerance: Understands and corrects common misspellings to still show desired products.

  • Enhanced Filters: Powers the fast, layered navigation that helps shoppers seamlessly refine their choices.

In short, Magento 2 Elasticsearch is the mandatory backend technology that ensures your store’s search is a sales-driving asset, offering customers a quick and satisfying way to find exactly what they want.

Google Search

Preparing for Elasticsearch Integration (Elasticsearch Magento 2 Setup)

Before running a single command or clicking "Save Config," proper preparation is the key to a smooth and successful setup. Rushing into configuration without these foundational steps is the most common cause of errors and downtime. Think of this phase as gathering your tools and blueprint before building.

Here is your checklist to prepare for the Elasticsearch Magento 2 setup.

1. Verify Version Compatibility

Your first and most critical step is to check the official compatibility matrix. Not every version of Elasticsearch works with every version of Magento 2. Using mismatched versions is a guaranteed path to failure. You can find this information in the official Magento 2.4.x System Requirements or Adobe Commerce Release Notes. For example, Magento 2.4.6 is typically compatible with Elasticsearch 8.x and OpenSearch 2.x, but you must confirm this for your specific Magento version.

2. Choose Your Deployment Strategy

You should decide where your Elasticsearch engine will run, as this impacts complexity, cost, and performance. The simplest option for a development environment is a local or on-server installation, where Elasticsearch runs on the same server as Magento. However, this is not recommended for production due to resource contention.

For a production store, a dedicated server or VPS offers better performance and scalability. The most reliable and hands-off production option is a managed cloud service like Elastic Cloud, AWS OpenSearch Service, or Google Cloud Elasticsearch, which handles infrastructure, security, and scaling for you.

3. Ensure System Prerequisites

Your chosen server must meet specific technical requirements. Elasticsearch requires a Java Runtime Environment (JRE), typically a supported version of OpenJDK. You must also allocate sufficient server resources, including at least 1GB of dedicated RAM for Elasticsearch itself, with more required for large catalogs. Finally, confirm network connectivity; your Magento server must be able to communicate with your Elasticsearch server over the network, which often involves configuring firewalls to allow traffic on port 9200.

4. Gather Your Connection Details

Before configuring Magento, collect all necessary access information. This includes the hostname or IP address of your Elasticsearch server, which could be localhost, a private IP, or a cloud cluster URL. You will also need the HTTP port, typically 9200. Prepare a unique index prefix, such as magento2_, to avoid conflicts if the Elasticsearch instance is shared. For secured or cloud services, have your username and password ready.

5. Back Up Your Magento Store

As a final and mandatory precaution, always create a complete backup of your Magento files and database before beginning the integration. This provides a crucial safety net, allowing you to restore your store to a working state should anything go wrong during the setup process.

Configuring Elasticsearch in Magento 2 (Magento Elasticsearch Configuration)

With your Elasticsearch server running and your connection details in hand, you are ready to connect it to your Magento 2 store. This core configuration can be completed using one of two primary methods: the command-line interface for precision and efficiency, or the Admin Panel for a graphical approach. Both methods achieve the same essential goal of directing Magento's search queries to your powerful new engine.

Method 1: Configuration via Command Line (Recommended)

Using Magento's CLI is often the fastest and most reliable method, especially for development and staging environments. It ensures settings are applied directly and immediately. Open a terminal in your Magento root directory and run the following commands, replacing the example values with your actual connection details.

Set the search engine to Elasticsearch:

bash
bin/magento config:set catalog/search/engine elasticsearch7

Configure the connection host and port:

bash
bin/magento config:set catalog/search/elasticsearch7_server_hostname localhost
bin/magento config:set catalog/search/elasticsearch7_server_port 9200

Define a unique index prefix. This is crucial if your Elasticsearch instance is shared with other applications or website stages (e.g., staging vs. production):

bash
bin/magento config:set catalog/search/elasticsearch7_index_prefix magento2_

For managed cloud services or secured clusters that require authentication, you must also set the username and password:

bash
bin/magento config:set catalog/search/elasticsearch7_enable_auth 1
bin/magento config:set catalog/search/elasticsearch7_username your_username
bin/magento config:set catalog/search/elasticsearch7_password your_secure_password

Method 2: Configuration via the Admin Panel

If you prefer a graphical interface, you can configure everything from within the Magento Admin. Navigate to Stores > Settings > Configuration > Catalog > Catalog > Catalog Search.

In this section, you will find all the corresponding settings:

  1. Set Search Engine to "Elasticsearch 7."

  2. Under Elasticsearch 7 Server Settings, enter your Server HostnameServer Port, and a unique Index Prefix.

  3. If your server requires it, expand the Elasticsearch 7 Server Authentication section, set "Enable Auth" to "Yes," and enter your credentials.

  4. It is good practice to adjust the Server Timeout if needed; a value of 15 seconds is a robust starting point for most stores.

  5. Click Save Config at the top of the page.

Get in touch
with our expert

Discuss your project requirements and get a free estimate.

Get in touch
with our expert

Discuss your project requirements and get a free estimate.

The Critical Final Step: Reindexing

Changing the search engine does not automatically transfer your product data. You must reindex to populate Elasticsearch with your catalog information. This is a mandatory step regardless of your chosen configuration method.

Run the search-specific reindex command from your Magento root:

bash
php bin/magento indexer:reindex catalogsearch_fulltext

For a comprehensive refresh, you can safely reindex all Magento indexes:

bash
php bin/magento indexer:reindex

Once the reindexing process completes successfully, your store's search and layered navigation are now powered by Elasticsearch. You can verify the connection by returning to the Admin configuration page; it should display a confirmation message such as "Elasticsearch Engine is available."

Advanced Elasticsearch Features for Magento 2

Once Elasticsearch is configured and running, you have unlocked the foundation for fast, relevant search. However, to truly tailor the experience to your specific catalog and customer behavior, you can leverage several advanced native features within Magento 2. These tools move you from a standard search implementation to a finely-tuned discovery engine that can increase conversion rates and customer satisfaction.

Tune Search Relevance with Synonyms and Stop Words

One of the most powerful ways to align search results with customer intent is by managing synonyms and stop words. This is configured directly within the Magento Admin.

  • Synonyms ensure that queries for different terms return the same relevant products. For instance, you can map "cellphone," "mobile," and "handset" to each other, so a search for any of these terms yields a complete set of smartphones. This is managed under Marketing > SEO & Search > Search Synonyms. Enter pairs or groups of terms separated by commas.

  • Stop Words are common terms (like "the," "and," "of") that are ignored during search to improve performance and relevance. You can define a custom list of these words in Stores > Attributes > Search. Removing insignificant words helps focus queries on the meaningful keywords that truly match products.

Configure Query Length and Search Suggestions

To prevent unhelpful, single-character searches from taxing the system, you can set a minimum query length. This is found in Stores > Configuration > Catalog > Catalog > Catalog Search. A value of 2 or 3 is standard and optimizes backend performance.

More visibly, you can enable Search Suggestions (also in the Admin Configuration). When active, this feature uses popular search terms and results to provide real-time, dropdown suggestions as customers type in the search box, dramatically speeding up the product-finding process.

Optimize Index Management for Large Catalogs

For stores with massive or complex product catalogs, the basic indexing configuration may require adjustment. Within the same Catalog Search configuration area, you can modify the setting for the Maximum Number of Search Results to be displayed. Increasing this limit, which defaults to 10000, ensures that no relevant products are omitted from filtered results on category pages.

Additionally, you should consider your Elasticsearch server's own index configuration settings, such as the number of shards and replicas. These can be tuned for better data distribution and increased resilience of your search infrastructure.

Customize with the Catalog Search Index

For developers, the true power lies in the catalogsearch_fulltext index. You can extend this index to include custom product attributes with specific properties. By marking an attribute as "searchable" in its properties (Stores > Attributes > Product), you ensure its data is processed by Elasticsearch. This allows customers to find products based on highly specific criteria unique to your catalog.

Monitoring and Optimizing Elasticsearch Performance

After your Elasticsearch integration is live, consistent monitoring and optimization are essential to maintain speed, reliability, and a superior search experience. Proactive management helps identify bottlenecks before they impact customers and ensures your search infrastructure scales with your store's growth.

The key areas to manage can be organized into the following framework:

AreaAction & PurposeKey Tasks & Tools
Essential MonitoringTrack cluster health and performance metrics to prevent outages and slowdowns.• Monitor JVM Heap MemoryCPU, and Disk Usage via Elasticsearch API or Kibana.
• Track search Query Latency and Request Rates.
• Set up alerts for critical thresholds (e.g., high memory pressure).
Index & Query OptimizationTune configuration and analyze queries for efficiency and speed.• Review and adjust Shard/Replica counts for your data volume.
• Implement Index Lifecycle Management (ILM) for old data.
• Analyze Magento logs and Elasticsearch slow query logs to identify and optimize heavy searches.
Magento ConfigurationEnsure store settings support optimal search performance.• Verify the Magento Search Query Cache is enabled and sized correctly.
• Audit product attributes to index only those that are necessary and searchable.
• Keep Magento extensions and the Elasticsearch engine updated.

Integrating Elasticsearch with Custom Magento Modules

Custom Magento modules (e.g., for blogs or directories) are not searchable by default. To include their data in Elasticsearch results, you must extend the native indexing process. This ensures a unified search across all site content.

The integration involves these key development steps:

StepPurpose & Key Action
1. Define a Searchable EntityModel your custom data (like blog posts) so the indexer can process it.
2. Create a Custom IndexerBuild a class that fetches your module's data and formats it for Elasticsearch.
3. Declare the IndexerRegister your new indexer in your module's etc/indexer.xml file.
4. Extend Elasticsearch MappingDefine your custom fields and their data types in etc/search_engine.xml.
5. Modify Search QueriesAdjust the search logic to query both product and your new custom indices.

Development Notes: Ensure your indexer outputs clean data and define clear reindex triggers. You will also need to create frontend templates to display this custom content in search results. Test thoroughly using bin/magento indexer:reindex.

Final Thoughts: Unlock the Full Potential of Your Store Search

Implementing Elasticsearch is a critical step in building a fast, relevant, and scalable search experience for your Magento 2 store. By following the roadmap outlined in this guide, you lay a powerful foundation that can directly increase customer satisfaction and drive sales growth.

Ready to transform your site search into a major revenue driver? The expert team at Transform Agency specializes in flawless Magento Elasticsearch integrations. We ensure every step is executed perfectly. Reach out today to implement a high performance search solution tailored for your business.

FAQ

What is Elasticsearch in Magento 2?

Elasticsearch is the mandatory, high-performance search engine for Magento 2.4 and above. It replaces the older MySQL-based search to provide fast, accurate, and typo-tolerant product searches and filtered navigation, significantly improving the customer experience.

How do I enable Elasticsearch in Magento 2?

You can enable it via the command line using bin/magento config:set commands or through the Magento Admin Panel under Stores > Configuration > Catalog > Catalog > Catalog Search. You must first install and run Elasticsearch on your server or cloud before configuring the connection in Magento.

How do I check Elasticsearch status in Magento 2?

You can check the connection status by running the command curl -XGET 'http://localhost:9200/_cluster/health' from your Elasticsearch server. Within the Magento Admin, navigate to the same Catalog Search configuration page; a successful connection will display a confirmation message such as "Elasticsearch Engine is available."

How do I check the Elasticsearch version in Magento 2?

Query your Elasticsearch server directly using the command curl -XGET 'http://localhost:9200' to see version details in the response. In the Magento Admin, the version is often noted on the Catalog Search configuration page once the connection is successfully established.

yar

Written with the assistance of Yaroslav Tobolich

Senior Magento 2 Frontend Developer at TA

With 7 years of experience in the IT industry, Yaroslav specializes in e-commerce solutions. He has developed approximately 15 online stores, ranging from medium-sized shops to large marketplaces, gaining extensive experience across various industries including financial services, retail & distribution, and life sciences & healthcare. Skilled in Adobe Commerce, he excels in frontend development solutions for this CMS.

yar

Written with the assistance of Yaroslav Tobolich

Senior Magento 2 Frontend Developer at TA

With 7 years of experience in the IT industry, Yaroslav specializes in e-commerce solutions. He has developed approximately 15 online stores, ranging from medium-sized shops to large marketplaces, gaining extensive experience across various industries including financial services, retail & distribution, and life sciences & healthcare. Skilled in Adobe Commerce, he excels in frontend development solutions for this CMS.

Previous Magento 2 Theme Development Guide: Create a Custom Theme from Scratch Next Shopify Plus vs Magento: Navigating Your E-commerce Platform Choice
0 Comment(s)
To Top