2

Hello Magento Community,

I am new to Magento and have been tasked with updating our search from MySQL to use ElasticSearch6 (6.8).

I would like to use search synonyms but I see that there is a message on the search synonyms admin screen which indicates that Synonyms entered won't be used. Are synonyms not supported at all with the use of elasticsearch6? The ElasticSearch documentation shows that synonyms are supported.

Any guidance would be greatly appreciated.

Magento 2 ElasticSearch synonms

  • Just to make it updated, there is a support for Elasticsearch6 synonyms in recent Magento 2.3 versions ;) – dudzio May 15 at 14:11
1

I found that the best way to achieve this is to still use the synonyms admin page in Magento. I will have to run a cron job to create the synonyms.txt file and populate it with the synonyms stored in Magento, then place it in the analysis folder in ElasticSearch.

Adding ElasticSearch Synonyms TXT

curl -XPOST 'localhost:9200/my_custom_magento_index/_close'
curl -XPUT 'localhost:9200/my_custom_magento_index/_settings' -d '
{
    "index" : {
        "analysis.filter.synonym.synonyms_path" : "synonyms.txt"
    }
}'
curl -XPOST 'localhost:9200/my_custom_magento_index/_open'

ElasticSearch Synonyms TXT file

# Blank lines and lines starting with pound are comments.

# Explicit mappings match any token sequence on the LHS of "=>"
# and replace with all alternatives on the RHS.  These types of mappings
# ignore the expand parameter in the schema.
# Examples:
i-pod, i pod => ipod,
sea biscuit, sea biscit => seabiscuit

# Equivalent synonyms may be separated with commas and give
# no explicit mapping.  In this case the mapping behavior will
# be taken from the expand parameter in the schema.  This allows
# the same synonym file to be used in different synonym handling strategies.
# Examples:
ipod, i-pod, i pod
foozball , foosball
universe , cosmos
lol, laughing out loud

# If expand==true, "ipod, i-pod, i pod" is equivalent
# to the explicit mapping:
ipod, i-pod, i pod => ipod, i-pod, i pod
# If expand==false, "ipod, i-pod, i pod" is equivalent
# to the explicit mapping:
ipod, i-pod, i pod => ipod

# Multiple synonym mapping entries are merged.
foo => foo bar
foo => baz
# is equivalent to
foo => foo bar, baz

References:

https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html

https://www.paperlesspost.com/blog/teams/setting-up-elasticsearch-synonyms/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.