Cookies setting

Cookies help us enhance your experience on our site by storing information about your preferences and interactions. You can customize your cookie settings by choosing which cookies to allow. Please note that disabling certain cookies might impact the functionality and features of our services, such as personalized content and suggestions. Cookie Policy

Cookie Policy
Essential cookies

These cookies are strictly necessary for the site to work and may not be disabled.

Information
Always enabled
Advertising cookies

Advertising cookies deliver ads relevant to your interests, limit ad frequency, and measure ad effectiveness.

Information
Analytics cookies

Analytics cookies collect information and report website usage statistics without personally identifying individual visitors to Google.

Information
mageplaza.com

How To Configure Elasticsearch in Magento 2

Vinh Jacker | 12-18-2024

3 Steps To Configure Elasticsearch in Magento 2

Search functionality is a critical element of any eCommerce store, as it directly impacts user experience and conversion rates. Magento 2, a leading eCommerce platform, offers Elasticsearch—a robust, scalable, and high-performance search engine—as its default search solution. In this blog, we’ll explore the benefits, configuration, and optimization of Magento 2 Elasticsearch to help you harness its full potential.

What Is Magento 2 Elasticsearch?

Elasticsearch is an open-source search and analytics engine designed for speed and scalability. In Magento 2, Elasticsearch replaces the older MySQL-based search to handle complex queries and large datasets efficiently. It provides a seamless search experience for customers, allowing them to find products quickly and accurately.

Discover the comparison between Sphinx Search and Elasticsearch here

Benefits of Elasticsearch in Magento 2

  • Enhanced search performance: Elasticsearch delivers fast and accurate search results, even for stores with extensive product catalogs. It significantly reduces the time customers spend searching for items, enhancing their shopping experience.
  • Scalability: As your store grows, Elasticsearch can handle increasing amounts of data and traffic without compromising speed or performance. It’s ideal for businesses aiming for long-term scalability.
  • Advanced search features:
    • Autocomplete: Suggests relevant products as users type.
    • Synonyms: Handles alternate search terms to improve result relevance.
    • Stemming: Recognizes word variations (e.g., “run” vs. “running”).
    • Faceted search: Filters results based on attributes like price, brand, or category.
  • Improved search relevance: With features like fuzzy search and relevance scoring, Elasticsearch ensures customers get the most relevant results, even for misspelled queries.
  • Multilingual support: Elasticsearch supports multiple languages, making it ideal for global eCommerce stores catering to diverse audiences.
  • Analytics integration: Gain insights into search trends, customer behavior, and product performance by integrating Elasticsearch with analytics tools.

Prerequisites to Set Up Elasticsearch In Magento 2.4

Elasticsearch is a mandatory component for the Magento platform and must be installed and configured prior to upgrading to version 2.4.x.

Important: Adobe has discontinued support for Adobe Commerce 2.3.x and PHP 7.3. To maintain PCI compliance, it is essential to upgrade to Adobe Commerce 2.4.x and PHP 7.4.x.

For Magento 2.4.x installations, Elasticsearch is a required dependency, along with the following prerequisites:

  • Webserver: Apache or Nginx
  • MySQL: MySQL
  • PHP: 7.4.x or higher

Note: Magento 2.4.x is designed to work specifically with Elasticsearch version 7.6.x.

How to Install Elasticsearch in Magento 2

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.

How to Configure Elasticsearch in Magento 2:

Step 1: Configure Search Options

#1. From the Admin sidebar, select Stores. Then under Settings, select Configuration.

Configure Search Options

#2. In the panel on the left of the screen, under CATALOG, select Catalog.

Configure Search Options 2

#3. Click on Catalog Search to expand this section.

Configure Search Options 3

#4. In the Search Engine field, clear the Use system value checkbox and select the version of Elasticsearch that is installed on your server.

Configure Search Options 4

#5. 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.

#6. 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.

#7. 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.

#8. 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

Configure the Elasticsearch Connection

  1. Enter the Elasticsearch Server Hostname. The default is localhost
  2. Enter the Elasticsearch Server Port.
  3. Enter a prefix in the Elasticsearch Index Prefix field to determine the Elasticsearch index. For instance: Magento2.
  4. In the Enable Elasticsearch HTTP Auth field, select the Yes option to use HTTP authentication to suggest a username and password access Elasticsearch Server.
  5. Enter the number of seconds before the system times out to the Elasticsearch Server Timeout field. The default number is 15.
  6. To verify the configuration, click the Test Connection button.

Step 3: Configure Suggestions and Recommendations

Search suggestions and recommendations can affect server performance

  1. In the Enable Search Suggestions field, choose the Yes option. Then, take the following actions:

Configure Suggestions and Recommendations 1

  • 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.
  1. 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.
  2. When you finish your configuration, click on the Save Config button.

Step 4: Refresh your full-page cache

Method 1: From the Admin Panel

Refresh your full-page cache

  • From the Admin Panel, select System > Cache Management.
  • Select the Page Cache check box, confirm the Refresh selection, and then click Submit.

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
  • 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.

x
    Jacker

    With over a decade of experience crafting innovative tech solutions for ecommerce businesses built on Magento, Jacker is the mastermind behind our secure and well-functioned extensions. With his expertise in building user-friendly interfaces and robust back-end systems, Mageplaza was able to deliver exceptional Magento solutions and services for over 122K+ customers around the world.



    Related Post

    Website Support
    & Maintenance Services

    Make sure your store is not only in good shape but also thriving with a professional team yet at an affordable price.

    Get Started
    mageplaza services