Magento 2 Elasticsearch: Configuration Guide for Better Search Performance

Magento 2 Elasticsearch

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

The Magento platform has made setting up an ecommerce store and launching a website super easy for business owners without limitations. However, one of the most crucial parts of any ecommerce website is the search feature since there might be many categories and subcategories nested into each other. 

Magento stores without an efficient real-time search feature can drop your conversions. This is where Elasticsearch comes into play. Magento developers continuously work to bring new technology components that improve user experience

Magento 2 Elasticsearch is such a component that makes it super easy for users to find the right entity with smart search and short word queries. The Magento platform recommends installing Elasticsearch on the earlier versions of Magento 2.3x but with predefined configurations. 

This blog will walk you through the requirements to install Elasticsearch on Magento 2 with a step by step guide. 

What is Magento 2 Elasticsearch?

Elasticsearch is a full-text search solution that recommends suggestions related to the keywords. It is an advanced search and analytics engine with Magento 2 for fast, accurate, and scalable search functionality for Magento ecommerce stores. However, it is not just limited to search queries, it can perform store wide searches. 

Magento 2 Elasticsearch is a server-based tool that is capable of fast web content search capability. The fast response is due to the indexing service used for contextual search. Magento 2 Elasticsearch suggests products, images, pricing, ratings, and information to narrow the searches. 

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

Key Features of Magento 2 Elasticsearch:

Key features that set Magento 2 Elasticsearch apart are as follows:

  1. Elasticsearch delivers high speed search with rapid results even for stores with large volumes of data. 
  2. Uses advanced algorithms to show relevant results based on search queries.
  3. Filters result by attributes and entities like price, categories, color, and more. 
  4. Offers real-time search suggestions with autocomplete functionality to improve user experience. 
  5. Handles high amounts of data and traffic without downtime.
  6. Offers multi-language support for optimized stores serving a diverse customer base. 

How Does It Work in Magento 2?

Magento 2 Elasticsearch leverages its high-speed capabilities to index product data, resulting in fast query response. It performs advanced-level text analysis on search queries for accurate and relevant results. 

Prerequisites to Set Up Magento 2 Elasticsearch

According to the official Magento release, Elasticsearch 2.x and early 5.x versions are no longer valid and you need to update to the latest version to use Elasticsearch. Be sure to check compatibility before upgrading to avoid last minute conflicts.

To use Elasticsearch with Magento 2.4, you must fulfill the following requirements:

  • Web Server: Apache or Nginx.
  • Database: MySQL 5.7 or MySQL 8.0.
  • PHP: Version 7.4 or later (as supported by your Magento version).

Configure Server for Magento 2 Elasticsearch 

Follow the following steps:

1. Install Elasticsearch on Your Server

    • Access your server and log-in via SSH with sudo privileges. 
    • Add the Elasticsearch Repository, using the code: 

    sudo rpm –import https://artifacts.elastic.co/GPG-KEY-elasticsearch

    • Create the repository file, using the code: 

    echo “[elasticsearch]

    name=Elasticsearch repository

    Enhance Your CyerPanel Experience Today!
    Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

    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” | sudo tee /etc/yum.repos.d/elasticsearch.repo

    • Install Elasticsearch, using the code:

    sudo yum install elasticsearch

    • Start and Activate Elasticsearch, using the code: 

    sudo systemctl start elasticsearch

    sudo systemctl enable elasticsearch

    2. Configure on Magento 2

      • Edit the Elasticsearch configuration file, using the code: 

      sudo nano /etc/elasticsearch/elasticsearch.yml

      • Update the yaml setting, using the code: 

      network.host: 0.0.0.0

      http.port: 9200

      discovery.type: single-node

      • Restart Elasticsearch, using the code: 

      sudo systemctl restart elasticsearch

      3. Set Up CyberPanel for Magento Hosting

        • Set-up a website in Cyberpanel using the dashboard. Navigate to Websites> Create Websites and fill the details. 
        • Install Magento using CyberPanel’s Application Installer.

        4. Configure Magento to Use Elasticsearch

          • Navigate to Stores > Settings > Configuration > Catalog > Catalog Search to log-in to the Magento admin panel. 
          • Choose Elasticsearch 7 from the menu. 

            Enter Elasticsearch Details:
          • Host: localhost or your server’s IP.
          • Port: 9200.
          • Index Prefix: magento2.
          • Enable Autocomplete: Set to Yes.
          • Save configuration, using the code: php bin/magento indexer:reindex

          5. Verify Elasticsearch with Magento 2 

            Run the following code to test:
            curl -XGET ‘http://localhost:9200

            How to Install Magento 2 Elasticsearch in CyberPanel? 

            Installing Magento 2 Elasticsearch in CyberPanel is super easy. Here is how you can do so in a few easy steps:

            1. Log-in to your admin panel with the correct username and password. 
            2. Go to Manage Applications. 
            How to Install Magento 2 Elasticsearch in CyberPanel? - 1
            1. Click on Install. 
            How to Install Magento 2 Elasticsearch in CyberPanel? - 2
            1. And done! 
            Magento 2 elasticsearch installed

            Configuration for Magento 2 Elasticsearch via Admin Panel

            After successfully installing Magento 2 Elasticsearch in CyberPanel, you need to head back to the Magento platform to complete the configuration process. With the latest version of Magento 2, Elasticsearch has become a default add-on, making configuration super easy. 

            Here is how you can do it.

            1. Log-in to the Magento admin as administration. 
            2. Then click on stores> settings> configuration> catalog.
            3. Then tap on the catalog search section. 
            4. Start entering the following data:
              1. Minimum query length: the keyword length where elasticsearch will be enabled.
              2. Maximum query length: maximum length of the search query Magento will accept.
              3. Number of top search results to cache: enter the number of popular searches that the module would store. 
              4. Search Engine: Magento supports multiple search engines, but Elasticsearch is the default. Choose the appropriate Elasticsearch version (e.g., Elasticsearch 7).
              5. Autocomplete limit: set maximum number of similar searches.
              6. Elasticsearch server hostname: enter IP address or hostname. 
              7. Elasticsearch server port: enter proxy port. The default is 9200.
              8. Elasticsearch Index Prefix: set your default prefix magento 2. 
              9. Enable Elasticsearch HTTP Auth: Enable if authentication is required; provide credentials.
              10. Elasticsearch Server Timeout: Define server timeout limit. 
              11. Enable Search Suggestion: set to YES for suggestions. 
              12. Search Suggestions Count: define the count of suggestions. 
              13. Show Results Count For Each Suggestion: Select YES.
              14. Enable Search Recommendations: Set YES to display string recommendations. 
              15. Search Recommendations Count: set the count for search suggestions. 
              16. Show Results Count for Each Recommendation: set YES to display the result count for each suggestion. Recommendations may be part of advanced configurations or additional modules.

            Common Issues and Troubleshooting for Magento 2 Elasticsearch 

            IssueDescriptionTroubleshooting Steps
            Elasticsearch service not runningThe Elasticsearch server is not active or down.– Check service status: systemctl status elasticsearch.- Restart the service: systemctl restart elasticsearch.
            Incorrect Elasticsearch configurationMagento cannot connect to Elasticsearch due to incorrect settings.– Verify hostname and port in Magento Admin:Stores > Configuration > Catalog > Catalog Search.
            Unsupported Elasticsearch versionMagento requires a specific Elasticsearch version.– Check the Magento compatibility list.- Upgrade/downgrade Elasticsearch accordingly.
            No products in search resultsProducts are not indexed or indexing failed.– Reindex via CLI: bin/magento indexer:reindex.- Check indexing logs for errors: var/log/debug.log.
            Slow search performanceSearch queries take too long to return results.– Optimize Elasticsearch memory usage.- Increase JVM heap size in jvm.options.
            Search returns incomplete resultsSome products or attributes are missing in search results.– Check attribute settings: ensure they are searchable in Stores > Attributes > Product.
            Magento cron jobs not runningElasticsearch indexing is delayed due to cron jobs not executing.– Verify cron status: bin/magento cron:check.- Set up cron jobs if missing.
            Elasticsearch cluster health is yellow/redIndicates an issue with Elasticsearch cluster status.– Check cluster health with: curl -XGET ‘localhost:9200/_cluster/health?pretty’.- Resolve issues with node setup.
            SSL/TLS connection errorsMagento cannot connect to Elasticsearch over HTTPS.Verify SSL certificate validity.- Update Magento configuration for secure connections.
            Error: “No alive nodes found in your cluster”Elasticsearch is unreachable from the Magento server.– Check firewall and network settings.- Ensure Elasticsearch is accessible on the specified hostname and port.
            Outdated Magento or Elasticsearch pluginsCompatibility issues between Magento and Elasticsearch.– Update Magento and Elasticsearch plugins to their latest versions.

            Final Words!

            Once you are done setting up Magento 2 Elasticsearch, your store would be ready to generate higher sales with a fast performing search across all content types. With a superior user experience and real-time autocomplete recommendations, all your leads will convert into paying customers!

            Frequently Asked Questions: Magento 2 Elasticsearch

            1. What are the system requirements for Magento 2 Elasticsearch?

            Magento 2 supports specific Elasticsearch versions. Check Magento’s compatibility list and ensure your server meets the necessary hardware and software requirements.

            2. Why is Magento 2 not indexing products in Elasticsearch?

            This issue may occur due to cron job failures, incorrect settings, or indexing errors. Reindex using the CLI (bin/magento indexer:reindex) and ensure your cron jobs are running.

            3. How do I optimize Elasticsearch for better performance in Magento 2?

            You can optimize Elasticsearch by increasing JVM heap size, enabling caching, and fine-tuning query settings for faster response times.

            4. Can I use Elasticsearch with Magento open source?

            Yes, Elasticsearch is supported with Magento Open Source, starting from version 2.4. It powers search functionality and indexing, replacing MySQL search for better speed and accuracy.

            Marium Fahim
            Hi! I am Marium, and I am a full-time content marketer fueled by an iced coffee. I mainly write about tech, and I absolutely love doing opinion-based pieces. Hit me up at [email protected].
            Unlock Benefits

            Become a Community Member

            SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
            Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!