For any Magento 2 e-commerce store, the search function is the digital equivalent of a sales associate. A slow or irrelevant search experience can lead to customer frustration and lost revenue. Elasticsearch, a powerful, open-source, distributed search and analytics engine, has become the standard for powering fast, relevant, and scalable product searches in Magento.
Since Magento 2.4.x, it has been a mandatory requirement, completely replacing the older, less efficient MySQL search .
This comprehensive guide provides an up-to-date, step-by-step tutorial on how to install and configure Elasticsearch for Magento 2, covering version compatibility, server setup, Magento configuration, and post-installation optimization.
Understanding Elasticsearch and Its Importance for Magento 2
Elasticsearch is built on Apache Lucene and is designed to handle large volumes of data with incredible speed . Unlike a standard database search that performs linear scans, Elasticsearch creates an inverted index, allowing for near-instantaneous full-text searches. For a Magento store, this translates directly into a better user experience. Key benefits include:
- Faster Query Performance: Shoppers get search results in milliseconds, even in catalogs with hundreds of thousands of products. This speed is crucial for keeping bounce rates low and engagement high .
- Improved Search Relevance: It uses advanced algorithms to understand search context, offering features like “fuzzy” matching to correct typos and returning results based on relevance scores, not just exact keyword matches .
- Advanced Features: Elasticsearch enables powerful features out-of-the-box, including autocomplete suggestions (“search as you type”), advanced filtering (facets), and the handling of synonyms (e.g., recognizing that “laptop” and “notebook” are related) .
- Scalability: As your store grows, Elasticsearch can scale horizontally across multiple servers, ensuring that search performance remains consistently high .
Liquid Web notes that for Magento 2.4 and above, many hosting providers now automatically bundle an Elasticsearch container because it is so essential for store success, underscoring its status as a no-brainer for any serious e-commerce operation .
Pre-Installation Checklist: Compatibility and Requirements
Before beginning the installation, it’s critical to verify that your server environment meets all necessary requirements. Incorrect versions are the most common source of installation failures.
Magento and Elasticsearch Version Compatibility
The version of Elasticsearch you install must be compatible with your Magento version. Using an incompatible version will prevent Magento from connecting to the search engine.
- Magento 2.3.x: Supports Elasticsearch 5.x, 6.x, and has partial support for 7.x. It was an optional replacement for the MySQL search engine .
- Magento 2.4.x and Adobe Commerce 2.4.x: Elasticsearch 7.x is required. The MySQL search engine was completely removed in this version line. It is important to note that Elasticsearch 8.x is not officially supported by native Magento/Adobe Commerce without third-party plugins .
Server Environment Requirements
- Java: Elasticsearch is a Java application. For Elasticsearch versions up to 7.x, you need Java 8 or higher installed on your server. From version 7.x onward, Elasticsearch bundles its own Java Development Kit (JDK), but having the correct version of Java installed system-wide is still a recommended best practice .
- RAM: A minimum of 2 GB of RAM should be dedicated to Elasticsearch. For larger catalogs with high traffic, 4 GB or more is strongly recommended to ensure optimal performance .
- Operating System: While Elasticsearch can run on Windows and macOS, a Linux-based operating system (like Ubuntu, CentOS, or Debian) is the standard for production environments due to its stability and performance .
- Access: You will need SSH access to your server with sudo privileges to run installation commands.
Step-by-Step Elasticsearch Installation on Ubuntu (22.04 / 20.04)
This section provides the commands for installing Elasticsearch 7.x on a Debian-based Linux distribution like Ubuntu, which is a common setup for Magento hosting.
Step 1: Update System Packages
Always start by updating your server’s package list and upgrading existing packages to ensure you have the latest security patches and dependencies.
sudo apt update && sudo apt upgrade -y
Step 2: Install Java (if required)
Check if Java is installed by running java -version. If not, install OpenJDK 11.
sudo apt install openjdk-11-jdk -y
Step 3: Add the Official Elasticsearch GPG Key and Repository
To install Elasticsearch directly from the official source, you must add their GPG key and repository to your system’s sources list. This ensures you receive official updates.
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo sh -c 'echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list'
Step 4: Install Elasticsearch
Update your package list again (to include the new repository) and install Elasticsearch.
sudo apt update
sudo apt install elasticsearch -y
Step 5: Enable and Start the Elasticsearch Service
After installation, you need to enable the service so it starts automatically on server boot and then start it immediately.
sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch
You can verify that it’s running correctly by checking its status:
sudo systemctl status elasticsearch
The output should show “active (running)”.
Step 6: Verify the Installation
The final step is to confirm that Elasticsearch is responding to requests. Use the curl command to send a GET request to its default port (9200).
curl -X GET "localhost:9200/"
A successful installation will return a JSON response containing information about your Elasticsearch cluster, including the version number and a cluster name, along with the famous tagline: "You Know, for Search" .
Step-by-Step Elasticsearch Installation on CentOS 7 / RHEL
For servers running Red Hat Enterprise Linux or CentOS, the process uses the yum package manager.
Step 1: Install Java
Install OpenJDK 11.
sudo yum install java-11-openjdk-devel -y
Step 2: Import the Elasticsearch GPG Key and Add the Repository
Import the key and create the repository file.
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
Create a file named elasticsearch.repo in /etc/yum.repos.d/ with the following content:
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
Step 3: Install, Enable, and Start Elasticsearch
Install the package, then enable and start the service.
sudo yum install elasticsearch -y
sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch
Configuring Elasticsearch in the Magento 2 Admin Panel
With the Elasticsearch server installed and running, the next step is to configure Magento to use it as its search engine. All configurations are done within the Magento Admin panel.
Step 1: Access Catalog Search Configuration
Navigate to Stores > Configuration > Catalog > Catalog and then open the Catalog Search tab .
Step 2: Set the Search Engine and Connection Details
In the Search Engine dropdown, select the appropriate option. For a standard Elasticsearch 7.x installation, you would typically select “Elasticsearch 7.x”. If you are using a third-party module like Amasty’s, you would select their specific option (e.g., “Amasty Elasticsearch 8”) .
Then, fill in the connection details for your Elasticsearch server:
- Elasticsearch Server Hostname: Enter the hostname or IP address of your server. If Elasticsearch is installed on the same machine as your Magento instance, use
localhostor127.0.0.1. - Elasticsearch Server Port: The default port for Elasticsearch is
9200. - Elasticsearch Index Prefix: If you are using a single Elasticsearch instance for multiple Magento installations (e.g., a staging and a production site), enter a unique prefix for each store to prevent index collisions. Otherwise, you can leave the default, such as
magento2. - Enable Elasticsearch HTTP Auth: Set to “Yes” only if you have configured HTTP authentication on your Elasticsearch server, and then provide the username and password .
- Elasticsearch Server Timeout: You can define a timeout in seconds. The default value is 15 .
Step 3: Test the Connection
Before saving, click the Test Connection button. Magento will attempt to communicate with your Elasticsearch server using the details you provided. A success message will confirm that the connection is working. If it fails, double-check the hostname, port, and that the Elasticsearch service is running on your server .
Step 4: Save Configuration and Clear Cache
Click Save Config. After saving, you must clear the Magento cache. You can do this from the admin panel by going to System > Cache Management and flushing the Magento cache, or via the command line with php bin/magento cache:clean .
Post-Installation: Reindexing and Verification
The final technical step is to reindex the catalog search data. This process populates Elasticsearch with your product data.
Reindexing via Command Line
Connect to your server via SSH, navigate to your Magento root directory, and run the reindex command. You can either reindex only the catalog search index or all indexes.
php bin/magento indexer:reindex catalogsearch_fulltext
Or, to reindex everything:
php bin/magento indexer:reindex
Frontend Verification
Go to your Magento store’s frontend and perform a few searches. The results should appear quickly. You can also test more advanced features. For instance, if you search for a product with a typo (e.g., “lpatop” instead of “laptop”), a properly configured Elasticsearch with default “fuzzy” settings should still return relevant results .
Pro Tips: Optimizing Your Magento 2 Elasticsearch Setup
Beyond the basic installation, these expert tips can help you fine-tune Elasticsearch for even better performance and more relevant search results.
- Use a Dedicated Elasticsearch Plugin: While the native integration is good, consider a third-party extension like Amasty Elastic Search or Wyomind Improved Search. These tools move many advanced configuration options from the command line or code into the admin panel, allowing you to easily manage synonyms, stopwords, search weights for attributes, and autocomplete behavior without developer intervention .
- Fine-Tune Index Settings for Your Hardware: The default settings for Elasticsearch are conservative. For a production server with ample RAM, you can significantly improve indexing and query performance. Key settings to adjust in the
elasticsearch.ymlconfiguration file include theindices.memory.index_buffer_sizeand the number of threads in the thread pool (thread_pool.search.queue_size). - Implement Synonym Lists: Search relevance isn’t just about typos; it’s about understanding your customers’ language. Use the synonym management feature (either via a plugin or by configuring Elasticsearch directly) to link terms like “sofa,” “couch,” and “settee.” This ensures customers find what they’re looking for, regardless of the word they use .
- Monitor Performance with Kibana: Elasticsearch is often paired with Kibana, a visualization tool. Connecting Kibana to your Elasticsearch cluster allows you to analyze search queries, see what customers are searching for (and not finding), and monitor the overall health and performance of your search engine .
- Secure Your Elasticsearch Instance: By default, Elasticsearch listens on all network interfaces and has no authentication. For production, it is critical to bind Elasticsearch to localhost (if Magento is on the same server) or implement proper firewall rules. Better yet, enable Elasticsearch’s built-in security features or use a reverse proxy like Nginx to add HTTP Basic Authentication .
Frequently Asked Questions (FAQ)
Q: What happens if I don’t install Elasticsearch for Magento 2.4.x?
A: You cannot run Magento 2.4.x without it. The platform will not function correctly, and you will likely encounter errors related to catalog search and navigation. The MySQL search engine was completely removed in this version .
Q: Can I use OpenSearch with Magento 2.4.x?
A: Yes, many third-party extensions now offer compatibility with OpenSearch, which is a popular open-source fork of Elasticsearch. For example, Amasty offers an “Amasty Opensearch” option in their plugin . However, native Magento 2.4.x is primarily designed for and tested with Elasticsearch 7.x. Using OpenSearch often requires a compatibility plugin.
Q: How do I change the Elasticsearch index prefix?
A: The index prefix is set in the Magento Admin under Stores > Configuration > Catalog > Catalog Search. After changing the prefix, it is critical to run the reindex command (php bin/magento indexer:reindex) to rebuild the search index with the new prefix .
Q: Why is my “Test Connection” failing in the Magento Admin?
A: This is usually due to one of four issues: (1) The Elasticsearch service is not running on your server (sudo systemctl status elasticsearch). (2) The server hostname or port is incorrect. (3) A firewall is blocking port 9200. (4) Elasticsearch is configured to listen only on localhost, and you are trying to connect via a public IP. Verify each step, starting with the service status.
Q: Will Elasticsearch slow down my site if I have a huge catalog?
A: On the contrary, Elasticsearch is designed to excel with massive datasets. It will almost certainly be faster and more scalable than any other search option native to Magento. Its distributed nature allows it to handle huge volumes of data efficiently, provided your server has adequate RAM allocated to it .
Conclusion
Installing and configuring Elasticsearch for Magento 2 is a fundamental task for any store owner looking to provide a competitive, high-performance user experience. While the initial setup involves several technical steps—checking compatibility, installing Java, adding repositories, and running system commands—the process is well-documented and reliable. The payoff is substantial: a fast, scalable, and intelligent search engine that can dramatically improve how customers find products, directly impacting conversion rates and customer satisfaction. By following this guide, you can ensure your Magento 2 store is built on a solid, search-optimized foundation, ready to handle the demands of modern e-commerce. After successful installation, continue to monitor and refine your search settings, utilizing advanced features like synonyms and search logging to truly master the art of on-site search.
Pro Tips: Optimizing Your Magento 2 Elasticsearch Setup
Beyond the basic installation, these expert tips can help you fine-tune Elasticsearch for even better performance and more relevant search results.
- Use a Dedicated Elasticsearch Plugin: While the native integration is good, consider a third-party extension like Amasty Elastic Search or Wyomind Improved Search. These tools move many advanced configuration options from the command line or code into the admin panel, allowing you to easily manage synonyms, stopwords, search weights for attributes, and autocomplete behavior without developer intervention .
- Fine-Tune Index Settings for Your Hardware: The default settings for Elasticsearch are conservative. For a production server with ample RAM, you can significantly improve indexing and query performance. Key settings to adjust in the
elasticsearch.ymlconfiguration file include theindices.memory.index_buffer_sizeand the number of threads in the thread pool (thread_pool.search.queue_size). - Implement Synonym Lists: Search relevance isn’t just about typos; it’s about understanding your customers’ language. Use the synonym management feature (either via a plugin or by configuring Elasticsearch directly) to link terms like “sofa,” “couch,” and “settee.” This ensures customers find what they’re looking for, regardless of the word they use .
- Monitor Performance with Kibana: Elasticsearch is often paired with Kibana, a visualization tool. Connecting Kibana to your Elasticsearch cluster allows you to analyze search queries, see what customers are searching for (and not finding), and monitor the overall health and performance of your search engine .
- Secure Your Elasticsearch Instance: By default, Elasticsearch listens on all network interfaces and has no authentication. For production, it is critical to bind Elasticsearch to localhost (if Magento is on the same server) or implement proper firewall rules. Better yet, enable Elasticsearch’s built-in security features or use a reverse proxy like Nginx to add HTTP Basic Authentication .
Frequently Asked Questions (FAQ)
Q: What happens if I don’t install Elasticsearch for Magento 2.4.x?
A: You cannot run Magento 2.4.x without it. The platform will not function correctly, and you will likely encounter errors related to catalog search and navigation. The MySQL search engine was completely removed in this version .
Q: Can I use OpenSearch with Magento 2.4.x?
A: Yes, many third-party extensions now offer compatibility with OpenSearch, which is a popular open-source fork of Elasticsearch. For example, Amasty offers an “Amasty Opensearch” option in their plugin . However, native Magento 2.4.x is primarily designed for and tested with Elasticsearch 7.x. Using OpenSearch often requires a compatibility plugin.
Q: How do I change the Elasticsearch index prefix?
A: The index prefix is set in the Magento Admin under Stores > Configuration > Catalog > Catalog Search. After changing the prefix, it is critical to run the reindex command (php bin/magento indexer:reindex) to rebuild the search index with the new prefix .
Q: Why is my “Test Connection” failing in the Magento Admin?
A: This is usually due to one of four issues: (1) The Elasticsearch service is not running on your server (sudo systemctl status elasticsearch). (2) The server hostname or port is incorrect. (3) A firewall is blocking port 9200. (4) Elasticsearch is configured to listen only on localhost, and you are trying to connect via a public IP. Verify each step, starting with the service status.
Q: Will Elasticsearch slow down my site if I have a huge catalog?
A: On the contrary, Elasticsearch is designed to excel with massive datasets. It will almost certainly be faster and more scalable than any other search option native to Magento. Its distributed nature allows it to handle huge volumes of data efficiently, provided your server has adequate RAM allocated to it .
Conclusion
Installing and configuring Elasticsearch for Magento 2 is a fundamental task for any store owner looking to provide a competitive, high-performance user experience. While the initial setup involves several technical steps—checking compatibility, installing Java, adding repositories, and running system commands—the process is well-documented and reliable. The payoff is substantial: a fast, scalable, and intelligent search engine that can dramatically improve how customers find products, directly impacting conversion rates and customer satisfaction. By following this guide, you can ensure your Magento 2 store is built on a solid, search-optimized foundation, ready to handle the demands of modern e-commerce. After successful installation, continue to monitor and refine your search settings, utilizing advanced features like synonyms and search logging to truly master the art of on-site search.