How to configure Magento 2 to use Elasticsearch
Key takeaways
- Magento 2 Elasticsearch configuration connects catalog search to a search engine that can return faster product results.
- Magento 2.4 and later require Elasticsearch or OpenSearch for catalog search.
- The main settings include search engine, hostname, port, index prefix, timeout, and authentication.
- After saving Elasticsearch settings, test the connection, clear cache, and reindex catalog search.
Learn how to configure Magento 2 to use Elasticsearch, a versatile search engine for large and varied data sets.
Host Magento at full throttle.
Get secure, reliable Magento hosting so you can scale faster.
What is Elasticsearch in Magento 2?
Elasticsearch is a search service that helps Magento handle catalog search and product discovery. It allows shoppers to search large product catalogs faster than a basic database search can provide.
For Magento 2.4 and later, catalog search must use Elasticsearch or OpenSearch. MySQL is no longer a supported catalog search engine in Magento 2.4 and later.
Before you configure Elasticsearch in Magento 2
Before you update Magento search settings, confirm that the search service is installed, running, and compatible with your Magento version. You should also know whether the service runs on the same server as Magento, a separate server, or a container.
You’ll need the Elasticsearch or OpenSearch hostname, port, index prefix, and authentication details if your environment requires them. You should also have SSH access so you can clear cache, reindex catalog search, and test the service from the command line.
Magento 2 Elasticsearch configuration fields
Use this table to confirm what each Magento search setting controls before you save changes.
| Field | What it means | Common value | Notes |
| Search engine | The search service Magento should use | Elasticsearch 7 or OpenSearch | Choose the option supported by your Magento version |
| Server hostname | Where Magento can reach the search service | localhost, 127.0.0.1, private IP, or service name | Depends on your hosting setup |
| Server port | The port used by the search service | 9200 | Some hosts use a proxy or custom port |
| Index prefix | The prefix Magento adds to search index names | Store or environment name | Use a unique prefix for shared instances |
| Enable authentication | Whether Magento must use HTTP authentication | Yes or No | Depends on the search service setup |
| Username | Search service username | Varies | Required only when authentication is enabled |
| Password | Search service password | Varies | Required only when authentication is enabled |
| Server timeout | How long Magento waits for a response | Varies | Higher values may help slower environments |
Configure Elasticsearch in the Magento Admin Panel
Open Catalog Search settings
Log in to your Magento 2 admin panel.
From your dashboard, select Stores > Configuration.
From the Catalog drop-down menu, select Catalog, then expand Catalog Search.
Select the search engine
In the Search Engine field, select the search engine that matches your environment. Depending on your Magento version and hosting setup, this may be Elasticsearch 7 or OpenSearch.
Don’t guess based on old setup steps. Choose the engine that matches your Magento version, hosting environment, and supported system requirements.
Enter the hostname and port
Common hostname values include localhost, 127.0.0.1, a private IP address, or a service name. The common Elasticsearch port is 9200, but your hosting environment may use a different port.
Set a unique index prefix
When multiple sites share one Elasticsearch instance, each site needs a unique index prefix. Without one, cron-driven reindexing can overwrite another site’s search index.
This is especially important for staging and production environments that share one search service. A unique index prefix helps keep one site’s search index from interfering with another site’s index.
Add authentication details if needed
If your Elasticsearch or OpenSearch service requires HTTP authentication, enable authentication and enter the correct username and password. Leave authentication disabled only when your environment does not require it.
Test and save the connection
Click Test Connection.
If the test passes, clear cache and reindex catalog search. If it fails, review the hostname, port, and authentication settings before trying again.
Configure Elasticsearch with Magento CLI
You can also set Magento 2 Elasticsearch configuration values from the command line. This can help when you need to script the configuration, update staging, or configure search while the Admin Panel is unavailable.
From the Magento root directory, use commands like these:

If your search service requires authentication, add the authentication settings:

The exact configuration paths can vary by Magento version and search engine. For example, OpenSearch configurations may use different values in newer Magento versions. Confirm your Magento version before copying commands from an older tutorial.
Finalize the configuration
A passed connection test doesn’t finish the setup. Magento still needs cache and index updates before storefront search reflects the new search engine settings.
Refresh your full page cache
Refresh cache from the Admin Panel
From the dashboard, select System > Cache Management.
Select the Page Cache check box, confirm the Refresh selection, then click Submit.
Refresh cache from the command line
Log in to your Magento server, then issue:

You can also flush cache if your change requires a broader cache reset:

Reindex catalog search
Log in to your Magento server.
To reindex the catalog search index only:

To reindex all indexers:

For this configuration change, reindexing catalogsearch_fulltext is usually the most relevant first step. If other indexers also need attention, reindex all indexers.
Test Elasticsearch from the server
If Magento cannot validate the connection, test the search service from the server. Start with:

If Elasticsearch runs on another host or port, replace localhost and 9200 with the correct values. A successful response usually returns cluster details in JSON format.
If the command fails, check whether the service is running, whether the port is correct, and whether firewall or network rules block access. You may also need to review the Elasticsearch configuration file:

Hosted and containerized environments may use different hostnames, ports, or service names, so match the command to your hosting setup.
Localhost vs. a separate Elasticsearch server
Use localhost or 127.0.0.1 when Magento and Elasticsearch run on the same server. If Elasticsearch runs on a separate node, container, or managed service, use the correct internal hostname, private IP address, or service name.
Avoid exposing Elasticsearch publicly unless you have proper access controls in place. Search services can contain product and index data, and public access can create security and performance risks.
Troubleshooting connection errors
If Magento shows an error such as “Could not validate a connection to Elasticsearch,” start with the basics. Confirm the service is running, the hostname and port are correct, and Magento can reach the service from the server.
Check Magento logs if the Admin connection test fails or search pages return errors. Also review elasticsearch.yml, especially network binding and port settings, if you manage the Elasticsearch server directly.
If your store runs in a hosted or containerized environment, confirm the correct service name and port with your hosting provider before changing Magento settings.
Post-configuration testing checklist
After you configure Elasticsearch, test the storefront and search behavior.
- Search for several products on the storefront
- Test category pages and layered navigation
- Confirm suggestions or autocomplete if your store uses them
- Review Magento logs for search-related errors
- Confirm cron is running
- Confirm each environment uses the correct index prefix
Magento 2 Elasticsearch performance notes
Search performance depends on catalog size, query volume, server resources, heap size, indexing frequency, and whether Elasticsearch shares resources with other services.
Large catalogs or slow search may require more than a settings change. You may need to review CPU, memory, disk performance, cron, indexer mode, and whether Elasticsearch should run on a separate node.
Reverting to MySQL
If you experience issues with Elasticsearch and cannot resolve them, select MySQL for the Search Engine field and save. Then clear cache and reindex catalog search.
Use this only for older Magento 2 versions that still support MySQL catalog search. For Magento 2.4 and later, MySQL is no longer a supported catalog search engine, so you’ll need to resolve the Elasticsearch or OpenSearch configuration instead.
When to ask for support
Ask for support if Elasticsearch won’t connect, the service isn’t running, the version is incompatible, search is slow, indexing fails, or multiple stores share the same Elasticsearch instance.
Support can help review service status, host and port settings, index prefixes, server resources, logs, and search configuration before the issue affects shoppers.
Magento 2 Elasticsearch FAQs
Getting started with Magento 2 Elasticsearch
Magento 2 Elasticsearch configuration requires the right search engine version, correct connection details, a unique index prefix when needed, and follow-up steps like cache cleaning and catalog search reindexing.
Start by confirming the Elasticsearch or OpenSearch host, port, and index prefix before saving the Magento Admin configuration. Then test the connection, reindex catalog search, and check storefront search results.
If Elasticsearch setup, search performance, or server resources affect a live store, explore Liquid Web Magento hosting.
For 24-hour assistance any day of the year, contact our support team by email or through your Client Portal.
Ready to get started?
Get the fastest, most secure Magento hosting on the market
Additional resources
Best abandoned cart email solutions for Magento 2 →
Learn how to recover lost sales with Magento abandoned cart emails.
How to install Magento extensions →
Install extensions to add features and customize your store.
How to backup my cms tables on Magento 2 →
Discover how to back up cms tables to protect key store content.
