Magento 2.4+ and Elasticsearch

Magento 2.4 has completely switched from using MySQL as its main search or listing engine to Elasticsearch.

Elasticsearch is used for searching, and also listing of any product or products in the store. When a customer opens a category page, he receives results filtered and sorted out by Elasticsearch, making Elasticsearch a necessary service in running the latest Magento store. Without its service, Magento will not be able to display products on the category page.

Elasticsearch Pros

Why has Magento made such a major change? See the Magento documentation for several major points.

We believe that the main point here is whether Elasticsearch gives a better performance than MySQL if we want to run a layered navigation filtering query. Elasticsearch can filter products with products’ attributes and return the aggregate number of products available faster and with lower usage of server resources.

From our experience, Elasticsearch is a solid solution. It can be easily installed and configured. It is stable and does not require a lot of attention from a server administrator. If necessary, it's easier to expand the number of Elasticsearch servers and create a cluster.

Elasticsearch Cons

The main disadvantage of Magento 2.4 is a complete drop-off, to the support of MySQL search. Elasticsearch is a must-have requirement. You can't run a store without it.

At the moment, many Magento merchants may not find it easy to update their stores because their host provider does not support Elasticsearch.

There are three possible solutions to this problem:

  1. The merchant may move the store for another hosting provider. Probably the new host will be more expensive than the previous one; Or
  2. The merchant can use a remote Elasticsearch server. For example, Elasticsearch cloud services or Amazon Elasticsearch service. Anyhow this option is not cheap.
  3. The merchant can install our Elastic Search Ultimate extension, as this extension has a MySQL search mode. It assigns all Magento requests to MySQL instead of Elasticsearch. Thus, Magento 2.4 can work without Elasticsearch, using MySQL only.

Supported Elasticsearch Versions

Magento 2.4 has dropped the support of Elasticsearch versions 2.x, 5.x, and 6.x as well.

If you have this version, you definitely should upgrade your Elasticsearch before upgrading your Magento. Also, don't upgrade the Elasticsearch to the latest version because Magento 2.4 officially has the support of only 7.6.x and may not, for instance, work correctly with 7.8.x.

The upgrade process of the Elasticsearch engine is described here. To upgrade from 2.x, 5.x, 6.x, it requires a restart of Elasticsearch service. So you probably will have some downtime during this process.

Common Elasticsearch Errors & Solutions

When you use Magento 2.4, you may see errors that are related to Elasticsearch. We have collected these common errors and have provided the necessary solutions to it.

Could not validate a connection to Elasticsearch. No alive nodes found in your cluster

This error means that Magento can't connect to Elasticsearch. It might be possible that your Elasticsearch is not running. To check your Elasticsearch status run:

curl -X GET "localhost:9200/_cluster/health?pretty"

You should receive an output like:

{
  "cluster_name" : "elasticsearch_brew",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 1,
   ...
  "active_shards_percent_as_number" : 50.0
}

Check the status field for the following colors; If the status is "green" or "yellow", it means that Elasticsearch is ready to grant your requests. If the status is "red", it means that for some reason, Elasticsearch is not fully functioning. For more details, you need to check the Elasticsearch logs.

If you receive a message like curl: (7) Failed to connect to localhost port 9200: Connection refused, it means that Elasticsearch is down. Try to restart it. If restarting doesn't help, check the Elasticsearch logs, or contact your host provider.

cluster_block_exception [FORBIDDEN/12/index read-only / allow delete (api)]

This error means that you are running out of disk space. Even if you have 10% of disk free space, Elasticsearch may trigger this error. Try to free some disk space for Elasticsearch indexes.

As a temporary solution, you should run the following command:

curl -XPUT -H "Content-Type: application/json" https://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'

ElasticSearch Ultimate's support of Magento 2.4

As you may know, our company develops an ElasticSearch Ultimate extension. This extension extends the default Magento search, adds additional capabilities, and improves the search quality.

Specifically, for Magento 2.4 and other Magento versions, we have re-written our extension afresh. Therefore, we have removed the code, which was responsible for the support of older Magento versions, and added some brand new features.

Our extension uses most of Elasticsearch capabilities and greatly improves the search quality and extends the search functions of Magento 2.4.

Also, as mentioned above, our extension has an option of running Magento 2.4 without Elasticsearch. It will need the use of MySQL as a search engine. This option will be useful to merchants who cannot move for a more expensive hosting plan now.

All merchants who are already using our extension in their various stores will be able to upgrade their extensions for free when they upgrade their Magento.

Final thoughts

Elasticsearch is a solid solution, as its usage will greatly improve the speed and stability of Magento stores. Before upgrading to Magento 2.4, you must be sure you have installed Elasticsearch and that it has the same version Magento needs.

Elasticsearch has its nuances and extensive configuration settings. If you do not have a lot of experience with this solution, it's good to double-check everything in a test environment before rolling updates on production.

Questions? Ask us in the comments.

Maria Tkachuk

Ecommerce Specialist

Maria is a seasoned Ecommerce Specialist, dedicated to transforming online businesses with her strategic insights and hands-on expertise.

Keep Learning

Loading...