What is the correct way to change an indice's stemmer on Elasticsearch when using magento
I have a Magento 2 site with product titles and descriptions in Portuguese, that uses Elasticsearch as the catalog search engine. When I search for terms with accents the search results quality is very poor. Taking a stab at the issue I found out that magento creates the indices with an english stemmer, which is not appropriate for my case, as seen in the following image:
I know I can change the stemmer to be in portuguese, via direct manipulation on elasticsearch, but upon each
magento indexer:reindex the old indice is deleted and a new one is created again with english, so that would not be a feasible solution.
Further digging into the issue I found that there's an
esconfig.xml in the
Magento_Elasticsearch module which is base to
Magento_Elasticsearch6, with the following structure
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Elasticsearch:etc/esconfig.xsd"> <stemmer> <type>stemmer</type> <default>english</default> <de_DE>german</de_DE> <en_US>english</en_US> <es_ES>spanish</es_ES> <fr_FR>french</fr_FR> <nl_NL>dutch</nl_NL> <pt_BR>portuguese</pt_BR> </stemmer> <stopwords_file> <default>stopwords.csv</default> <de_DE>stopwords_de_DE.csv</de_DE> <en_US>stopwords_en_US.csv</en_US> <es_ES>stopwords_es_ES.csv</es_ES> <fr_FR>stopwords_fr_FR.csv</fr_FR> <nl_NL>stopwords_nl_NL.csv</nl_NL> <pt_BR>stopwords_pt_BR.csv</pt_BR> </stopwords_file> </config>
I wonder what is the proper way to override this file as to make Magento use a portuguese stemmer by default?
I think No need to override any file.
Try below with the default system configuration, Magento does provides such a setting.
Stemmer works on the value configured on the store level.
- On the Admin sidebar, go to Stores > Settings > Configuration and switch to the specific store view if the website has multiple store views.
- In the left panel under General, choose General.
- Expand Expansion selector the Locale Options section
Use Websiteif exists and Set Locale to the store language to Portuguese (Brazil) or Portuguese (Portugal) as per your convenience.
- Save config and clear cache if needed.
Run the catalog search index command -
php bin/magento indexer:reindex catalogsearch_fulltext
For more info, https://docs.magento.com/m2/ce/user_guide/stores/locale-options.html#to-set-the-store-locale