UPCOMING: Magento 2 Bootcamp of four days in The Netherlands (April 29th - May 2nd)
background

September 26, 2020

Removing ElasticSearch from Magento 2.4

Yireo Blog Post

Ok, this might be click-bait: This blog is not only about removing ElasticSearch from Magento 2.4. It is about removing all search functionality from Magento 2: The quick search, the indexing, the advanced search ... and ElasticSearch. Is that a wise idea? I don't know, but it works for me.

The reasons why I started to wreck things

The main reason I wanted to have such a module is that I'm using Magento 2 myself for some small shops that actually do not require Magento. The strategy of Magento that is moving the technology more and more towards a complex enterprise stack, does not help me with maintaining those shops. For instance, one shop holds about 20 products (which makes it a bad fit for Magento, I know, but it is used for my own educational purpose) and does not require a search. And definitely, it does not require ElasticSearch to optimize that search.

In short, I started to hack my way into removing search from Magento: All search, not just ElasticSearch, but MySQL search as well.

Meet the Yireo_RemoveSearch package

So, meet the Yireo_RemoveSearch package: A package available on GitHub to allow you to apply a series of tricks to remove search effectively from Magento. Feel free to try it out. If you bump into issues, feel free to open an Issue on GitHub. But know also that this is not an official Magento solution, it is breaking some things on purpose and the Force must be strong with you to adapt this approach.

Ugly facts about this approach

So here is some insight into what the package is doing:

  • It is requiring you to manually apply the composer replace trick to replace the relevant Magento search packages with a wild-card *, which in effect removes the package from your vendor/ folder. This composer feature is badly documented and it leads to weird issues. This leads to the second step: Installing the Yireo_RemoveSearch package is not done using a normal composer approach.

  • When installing the package, you can not use the regular composer require abc command. Instead, you have to use composer require yireo/magento2-remove-search --no-update and then composer update. Sometimes it is also needed to remove the vendor/ folder and the composer.lock file. It is all needed to force composer to recalculate all dependencies. Do not argue with me here. If you don't like this, don't use composer replacements.

  • With all of the core search packages gone, numerous things in the Magento core are broken. Magento has not refactored the search architecture fully yet and because of this, the hacking needs to start. The package contains a subfolder Magento to override specific classes in the namespaces Magento\Search and Magento\CatalogSearch. Most of the classes are this subfolder are empty shells, skeleton classes just to satisfy the DI compilation process. This kind of works.

Current status: Kind of OK

The end result is that you can run Magento without ElasticSearch or any search engine for that matters. I have now tested this out on various sites (two of which are live) and this seems to work ok. It has been tested for Magento 2.3.5 and 2.4.0. And it might work for other Magento versions as well, but it might also be that third party extensions (or older core modules) depend on Magento\Search or Magento\CatalogSearch classes that have not been recreated yet.

One thing that is definitely broken is the GraphQL endpoint products. I will work on this soon. Let me know if you are also running this approach to hack the search out of Magento.

Posted on September 26, 2020

About the author

Author Jisse Reitsma

Jisse Reitsma is the founder of Yireo, extension developer, developer trainer and 3x Magento Master. His passion is for technology and open source. And he loves talking as well.

Sponsor Yireo

Looking for a training in-house?

Let's get to it!

We don't write too commercial stuff, we focus on the technology (which we love) and we regularly come up with innovative solutions. Via our newsletter, you can keep yourself up to date on all of this coolness. Subscribing only takes seconds.

Do not miss out on what we say

This will be the most interesting spam you have ever read

We don't write too commercial stuff, we focus on the technology (which we love) and we regularly come up with innovative solutions. Via our newsletter, you can keep yourself up to date on all of this coolness. Subscribing only takes seconds.