A
A
Andrey2018-11-08 15:50:48
elasticsearch
Andrey, 2018-11-08 15:50:48

How do synonyms work in Elasticsearch?

I am creating an index with a customized parser. I set rules for synonyms.
Example from documentation:

curl -X PUT "localhost:9200/test_index" -H 'Content-Type: application/json' -d'              
{
    "settings": {
        "index" : {
            "analysis" : {
                "filter" : {
                    "synonym" : {
                        "type" : "synonym_graph",
                        "synonyms" : [
                            "lol, laughing out loud",
                            "universe, cosmos"
                        ]
                    }
                }
            }
        }
    }
}
'

Next, I created a document:
curl -X PUT "localhost:9200/test_index/_doc/2?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "laughing out loud"
}
'

Now, in theory, on request
curl -X GET "localhost:9200/test_index/_search?q=lol&pretty"

The entry created earlier should be returned - name: "laughing out loud"
But it does not return for me.
Tell me what I'm doing wrong, maybe I missed something or the procedure is wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2018-11-08
@leahch

In addition to setting a filter, you also need to create your own analyzer and attach it to the desired field through mapping. Here, in a recent article on Habré, the correct mapping is done - https://habr.com/post/428814/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question