What is Elasticsearch and how to configure a query in Magento 2?
What is Elasticsearch in Magento 2?
Elasticsearch in Magento 2 is a search engine that allows you to enable search tools on your website and provide users with relevant information. This product can take data from any source, any format, and search and visualize it in real-time. Also, Elasticsearch supports multiple languages, stop words, and synonyms.
Unlike MySQL, Elasticsearch is highly customizable, extendable through plugins. You can build a robust search without much knowledge quite fast. While Elasticsearch is a must in the Magento 2.4 version, you can still make it more user-friendly with the Elastic Search extension.
To configure the query in the Elastic Search extension, do the following:
Step 1. Make a general configuration of the module by setting up the connection and setting Autocomplete suggestions & Spelling correction.
Step 2. Then navigate to Admin Panel > Stores > Product and choose a needed attribute. Next, go to the Storefront Properties option and switch the Use in Search option to Yes to add a product attribute to a search query configuration.
Step 3. Now, go to the Catalog settings section on the Configuration tab and specify the Search Query Settings for each product attribute:
Step 4. Specify the way to combine keywords in a search query for each product attribute:
- OR to return results that contain either the first and second(more) word of the query.
- AND to return only results that contain all the words of the query.
Step 5. After that, complete Indexation Settings:
- In the Char Mapping setting, you need to specify characters and values to convert them into.
- Switch the Use Inbox Stopwords option to Yes if you want to apply a default set of stopwords and choose the language in the shown dropdown.
- Switch the Use Inbox Stemming option to Yes if you want to use stemmed words in a search. This feature allows your customers to search items by the root form of the word.
Step 6. Save the changes.
What version of Elasticsearch Magento 2 supports?
The minimal Magento 2 Elasticsearch version varies and depends on the version of Magento you use. Since Magento 2.4 release, all installations must be transferred from MySQL search engine to Elasticsearch. The minimal Magento 2.4 Elasticsearch version is 7.6. Elasticsearch 2.x, 5.x, and 6.x versions are not supported.
How to configure the vanilla Magento 2 Elasticsearch query?
To configure the Magento 2 Elasticsearch query, go to Stores > Settings > Configuration. Then open the Catalog tab and click Catalog. Navigate to the Catalog Search section. Here you can set up the search query minimal and maximal length, the number of top search results to cache, indexer, and autocomplete limits.
Now you can go to the storefront and test if the search works correctly. Check the user guide for more details about extension settings.
The Elastic Search extension provides a wide range of features but to provide the user with a good search experience on any device, use the PWA add-on for Elastic Search to guarantee your customers a hassle-free product search from any device.