Since version 2.4, the Magento 2 e-commerce system can no longer use MySQL search. Regardless of the improved quality of search results provided by Elasticsearch or other search providers, the discontinuation of MySQL search can be viewed critically.
The installation of a Java Virtual Machine, which is required to run Elasticsearch, is not supported by some web hosts. This ultimately means that the Elasticsearch instance has to be hosted externally. This results in additional costs and potential sources of errors.
At our online agency, we use the instance provided directly by Elastic. When setting it up, it is advisable to pay close attention to the hourly prices. An incorrectly configured deployment can otherwise quickly result in ten times the costs.
Once the deployment has been fully configured, you will receive a password that you should make a note of.
In the next step, we open our Magento 2 backend in parallel under:
Stores -> Configuration -> Catalog -> Catalog -> Catalog Search
In this tab, select Elasticsearch as the search engine, using the version that is running on the server.
In the Elasticsearch Server Hostname tab, we now need the data from the Elasticsearch backend.
On the Elastic Cloud homepage, you will now see a list of all created deployments. Select the desired deployment and you will be redirected to a new overview.
Here you will find an item called Applications. Under Elasticsearch, select Copy endpoint. Now return to the Magento 2 backend and paste the endpoint into Elasticsearch Server Hostname.
Here is an example of what the endpoint could look like:
https://my-deployment-fg1234.es.eu-central-1.aws.cloud.es.io:9243
Here, remove the numbers from right to left up to the colon and copy the numbers into Elasticsearch Server Port. The colon in Server Hostname must of course also be removed.
For Elasticsearch Index Prefix, you can simply keep the default value magento2 as long as you are using the deployment for only one Magento instance.
Next, select yes in the Enable Elasticsearch HTTP Auth dropdown menu. Once this has been done, additional fields will appear. Enter elastic under Elasticsearch HTTP Username.
Under Elasticsearch HTTP Password, enter the password that was provided when the deployment was created.
In the next step, check the connection using Test Connection. If everything has been entered correctly, the text will change to “Successful! Test again?”.
If a 401 error appears, there is an issue with the login credentials, which should be checked if necessary.
As the final step, you need to reindex the catalog via SSH. To do this, navigate to the Magento 2 root directory and execute the following command:
bin/magento indexer:reindex catalogsearch_fulltext
This step is very important, as otherwise the search may display error messages.
You can now test Magento's new catalog search.
With this change, your online store is now equipped for the future.
