With a big catalog of 224+ extensions for your online store
How To Configure Elasticsearch in Magento 2
Elasticsearch is a robust and highly scalable catalog search solution which is used by high-volume sites such as eBay, Wikipedia, and GitHub. With the support of Magento 2 Elasticsearch, store admins can implement both search suggestions and recommendations, giving a better customer experience to make extra sales.
In this article, you will be instructed to configure Elasticsearch in Magento 2.
Tip: Download Elasticsearch by Mageplaza to enable any search, auto-corrected spelling, synonym searches, behaviour tracking, and more.
Discover the comparison between Sphinx Search and Elasticsearch here
What Is Magento 2 Elasticsearch?
Elasticsearch is a distributed and open search and analytics engine. It supports various types of data, including text, numbers, and geospatial information. Built on Apache Lucene, it acts as a full-text search solution, providing related keywords and complete queries based on user input.
Elasticsearch also enables store-wide search functionalities, suggesting related products, images, prices, ratings, and more to enhance search results.
From Magento version 2.4 onwards, Elasticsearch has become the default catalog search engine for Adobe Commerce. It is an important component of Magento installations but can be disabled if necessary. This feature greatly enhances the customer experience by delivering quicker and more relevant search results, potentially improving conversion rates.
How does Elasticsearch Work?
Elasticsearch provides quick and reliable search results by using indexing. These indices are organized collections of documents that make it easy to retrieve data quickly and keep related documents together.
When Elasticsearch receives raw data from different sources, like logs and web applications, it processes and indexes that data. This indexing allows users to conduct detailed searches and get summaries of their information through aggregations.
Prerequisites to Set Up Elasticsearch In Magento 2.4
To use Magento 2.4, you must install and configure Elasticsearch, as it is a required add-on for the platform.
Note: Adobe no longer supports Adobe Commerce 2.3.x and PHP 7.3. It’s essential to upgrade to Adobe Commerce 2.4.x and PHP 7.4.x to maintain PCI compliance.
For Magento 2.4.x, you need to have Elasticsearch installed along with these additional requirements:
- Webserver (Apache or Nginx)
- MySQL
- PHP
Note: Magento requires Elasticsearch version 7.6.x for all installations.
Benefits of Magento 2 Elasticsearch
Enhance searching experience
Poor search engine performance can frustrate customers and lead them to abandon your site (high bounce rates). Elasticsearch helps with this by providing fast results and suggesting relevant options in real time, keeping users engaged. Additionally, auto-completion and correction of typos or misspellings reduce wasted time and improve search accuracy by finding related terms and suggesting better phrasing. Overall, Elasticsearch delivers a smoother search experience that keeps customers happy and exploring your site.
Provide quick search
Elasticsearch speeds up searches significantly compared to traditional SQL methods. It achieves this through two key features:
- Fast Retrieval: Built on Lucene and using distributed inverted indexes, Elasticsearch excels at full-text searches, retrieving relevant keywords in under 10 seconds.
- Search Result Caching: It efficiently caches search queries with filters, allowing for almost instant retrieval of results when a search matches a cached filter. This minimizes the time between indexing a document and making it searchable. In simpler terms, Elasticsearch finds what you’re looking for quickly and keeps recently searched items readily available, leading to a much faster and more responsive search experience.
Offer high-performance data handling
Elasticsearch’s distributed architecture is key to its scalability and data handling capabilities. Documents are split and stored across multiple servers (shards) with automatic replication for redundancy. This allows Elasticsearch to handle massive datasets and scale up to thousands of servers effortlessly. In simpler terms, it’s built to grow as your data needs grow, making it easy to handle enormous amounts of information.
Support schema-free
Elasticsearch is schema-free, meaning it doesn’t require a pre-defined structure for your data. It stores data in JSON format (JavaScript Object Notation) and automatically detects the structure as you add documents. This allows for flexibility: you can add new data with different properties without needing to manually adjust the schema. Elasticsearch uses defaults for indexing data types, but you can specify them if needed. Overall, this schema-free approach makes it easy to store and search a wide variety of data.
Install Elasticsearch
In this process, we will install Elasticsearch with SSH access after your application’s server setup on Ubuntu. Please Note we assume your application is already set up on Ubuntu or any other hosting server. Let’s get started!
Step 1: Update Package Lists
First, update the system’s package lists to ensure you have the latest versions of the repositories:
sudo apt update
Step 2: Install OpenJDK (Java)
Elasticsearch requires Java, so, you need to install the default OpenJDK package:
sudo apt install openjdk-11-jdk -y
After the installation, verify the Java installation:
java -version
Step 3: Add Elasticsearch GPG Key
Download and install the Elasticsearch GPG key:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
Step 4: Add Elasticsearch Repository
Next, add the Elasticsearch APT repository to the system:
sudo sh -c 'echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" > /etc/apt/sources.list.d/elastic-8.x.list'
Step 5: Install Elasticsearch
Update the APT package lists again, then install Elasticsearch:
sudo apt update
sudo apt install elasticsearch -y
Step 6: Configure Elasticsearch
Before starting Elasticsearch, configure it as needed. Open the Elasticsearch configuration file:
sudo nano /etc/elasticsearch/elasticsearch.yml
You can change some settings such as:
- cluster.name: Name of your Elasticsearch cluster.
- node.name: Name of the current node.
- network.host: Set this to localhost or 0.0.0.0 for public access.
Step 7: Start and Enable Elasticsearch Service
Start the Elasticsearch service:
sudo systemctl start elasticsearch
Enable Elasticsearch to start on boot (option):
sudo systemctl enable elasticsearch
Step 8: Verify Elasticsearch is Running
Check if Elasticsearch is running by making a request to the service:
curl -X GET "localhost:9200/"
If everything is set up correctly, you should see a response with details about your Elasticsearch cluster.
Step 9: Adjust Firewall Settings (if applicable)
If you need to access Elasticsearch from outside the server, ensure that port 9200 is open on the firewall:
sudo ufw allow 9200
Now, Elasticsearch should be successfully installed and running on your server.
3 Steps to Configure Elasticsearch in Magento 2:
Step 1: Configure Search Options
- From the Admin sidebar, select Stores. Then under Settings, select Configuration.
- In the panel on the left of the screen, under CATALOG, select Catalog.
- Click on Catalog Search to expand this section.
- In the Search Engine field, clear the Use system value checkbox and select the version of Elasticsearch that is installed on your server.
- Elaticsearch (Deprecated) Elasticsearch 2.0+ has reached the end of life and is considered inactive development or maintenance.
- Elaticsearch 5.0+ (Default) Elasticsearch 5.0+ is planned for the end of life.
- Elasticsearch 6.0+ (Recommended) For the best performance, we highly recommend that you use the latest version of Elasticsearch 6.0+.
-
In the Enable EAV Indexer field, select the Yes/ No option to enable/ disable the Product EAV indexer. This functionality increases indexation speed and keeps the indexer from being used by 3rd party extensions. This feature does not display the system value Search Engines.
-
To restrict the length and word count of search query text, set the Minimal Query Length and Maximum Query Length.
Note: The values for this minimum and maximum range must be compatible with the corresponding ranges in your Elasticsearch search engine configurations. For example, if you set these values to 2 and 300 in Magento, update the values in your search engine.
-
To restrict the number of popular search results to cache for faster responses, enter a number on the Number of top search results to the cache field.
-
To restrict the maximum number of search results to show for search autocomplete, set an amount for Autocomplete Limit. Limiting this amount enhances the performance of searches and cuts down the displayed list size. The default number is 8.
Step 2: Configure the Elasticsearch Connection
- Enter the Elasticsearch Server Hostname. The default is localhost
- Enter the Elasticsearch Server Port.
- Enter a prefix in the Elasticsearch Index Prefix field to determine the Elasticsearch index. For instance: Magento2.
- In the Enable Elasticsearch HTTP Auth field, select the Yes option to use HTTP authentication to suggest a username and password access Elasticsearch Server.
- Enter the number of seconds before the system times out to the Elasticsearch Server Timeout field. The default number is 15.
- To verify the configuration, click the Test Connection button.
Step 3: Configure Suggestions and Recommendations
Search suggestions and recommendations can affect server performance
- In the Enable Search Suggestions field, choose the Yes option. Then, take the following actions:
- Fill the Search Suggestions Count field with the number of search suggestions to offer.
- In the Show Results for Each Suggestion field, select the Yes option to display the number of results found for each suggestion.
- In the Enable Search Recommendations field, select Yes option to offer recommendations.
- Fill the Search Recommendation Count field with the number of recommendations to offer.
- In the Show Results Count for Each Recommendation field, select Yes to display the number of results found for each recommendation.
- When you finish your configuration, click on the Save Config button.
Step 4: Refresh your full-page cache
Method 1: From the Admin Panel
- From the Admin Panel, select
System > Cache Management.
- Select the
Page Cache
check box, confirm theRefresh
selection, and then clickSubmit.
Method 2: By the command line
To refresh your full-page cache, you can log in to your Magento server, then issue:
magento cache: clean
Step 5: Reindex catalog search
-
Log in to your Magento server.
-
Enter one of the following commands, but replace the angled brackets (<>) and everything between them with the indicated information.
Note: If you are a Nexcess Cloud client, will use your domain name; for example, mydomain.com/bin/magento.
- To reindex the catalog search index only:
php <your_Magento_install_dir>/bin/magento indexer:reindex catalogsearch_fulltext
- To reindex all indexers:
php <your_Magento_install_dir>/bin/magento indexer:reindex
Conclusion
The detailed instructions above hopefully gives you ideas on how to configure Elasticsearch in Magento 2. If you have questions on any steps, don’t hesitate to contact us. And if you would you like to provide all advanced techniques for searching online in your store, let the Ajax Search extension help you! Ajax Search for Magento 2 is the perfect solution to make your website more optimized and flexible in searching for products as well as enhance customer satisfaction and boost your online store sale.
FAQs
1. How to install Elasticsearch in Magento 2?
Follow these steps:
-
Step 1: Go to the Admin Panel
-
Step 2: Navigate to Stores> Configuration > Catalog > Catalog Search.
Afterward, you have the option to adjust Elasticsearch configurations, such as the server’s hostname, port, and authentication credentials.
2. Can Elasticsearch improve response times in Magento 2?
Sure! In the newest version of Magento, Elasticsearch is the default search engine. It’s really good at searching and finding things quickly because of its strong architecture and caching. This means you get search results faster and they’re more accurate.
3. How does Elasticsearch manage the display of top search results in Magento 2?
Elasticsearch does a good job handling lots of popular search results in Magento 2. It uses Apache’s indexing and caching tools to do this. These tools help Elasticsearch quickly find and show popular search results. Plus, it stores these results in a cache, so they show up even faster when you search again.
4. What happens with older versions of Magento 2 that are no longer supported when integrating with Elasticsearch?
For Magento versions, it’s really important to update to the newest one that works well with Elasticsearch to get the best performance. The latest Magento versions already have Elasticsearch built-in, so they continue to receive support and stay compatible.
Looking for Magento Development Company?
8+ years of experiences in e-commerce & Magento has prepared us for any challenges, so that we can lead you to your success.
Get free consultantRecent Tutorials
How to insert Order Attributes to Transactional Emails
How to insert Order Attributes to Transactional Emails
How to add Order Attributes to PDF Order Template
Explore Our Products:
People also searched for
- magento 2 elasticsearch
- elasticsearch magento 2
- magento 2 disable elasticsearch
- magento 2 elasticsearch configuration
- disable elasticsearch magento 2
- elastic search magento 2
- magento 2 elastic search
- magento 2 elasticsearch extension
- elasticsearch magento 2 extension
- magento elasticsearch
- elasticsearch magento 2 module
- magento elasticsearch extension
- magento 2 configure elasticsearch
- magento 2 elasticsearch module
- magento 2 enterprise elasticsearch
- magento 2 enable elasticsearch
- elasticsearch magento
- magento elastic search
- elastic search magento
- magento 2 elasticsearch demo
- magento 2 elasticsearch 6
- magento 2.3.1 elasticsearch
- elasticsearch suggester tutorial
- magento 2 setup elasticsearch
- 2.3.x, 2.4.x
Stay in the know
Get special offers on the latest news from Mageplaza.
Earn $10 in reward now!