Synonyms filter doesn't work in all modes when indexing

Hi, I have a problem when I tried to index data with a synonyms that read from file, that is an mapper_exception which giving me error like this:
{
"error" : {
"root_cause" : [
{
"type" : "mapper_exception",
"reason" : "analyzer [synonym_analyzer] contains filters [my_synonyms] that are not allowed to run in all mode."
}
],
"type" : "mapper_parsing_exception",
"reason" : "Failed to parse mapping [doc]: analyzer [synonym_analyzer] contains filters [my_synonyms] that are not allowed to run in all mode.",
"caused_by" : {
"type" : "mapper_exception",
"reason" : "analyzer [synonym_analyzer] contains filters [my_synonyms] that are not allowed to run in all mode."
}
},
"status" : 400
}

My Environment is:
{
"name" : "Daruma-Precision-3630-Tower",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "zaS3v33FRy2lbR_fq-ND6Q",
"version" : {
"number" : "7.6.1",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "aa751e09be0a5072e8570670309b1f12348f023b",
"build_date" : "2020-02-29T00:15:25.529771Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}

The Query that I used is:
PUT /laptops/?include_type_name=true
{
"settings": {
"index" : {
"analysis" : {
"filter" : {
"synonym_filter" : {
"type" : "synonym",
"synonyms" : [
"laptop, notebook",
"ram, memori"
]
},
"my_synonyms": {
"type": "synonym",
"synonyms_path": "my_synonyms.txt",
"updateable": true
}
},
"analyzer" : {
"synonym_analyzer" : {
"tokenizer" : "standard",
"filter" : ["lowercase", "synonym_filter"]
// "filter": ["my_synonyms"]
}
}
}
}
},
"mappings": {
"doc": {
"properties": {
"title": {
"type": "text",
"analyzer": "synonym_analyzer"
}
}
}
}
}

When I used synonyms that I hard coded in query it works and doesn't give me error..
Any advice or solutions to fix this? Thank you

1 Like

Hi yohannesss,

You set your synonym filter to "updateable", presumably because you want to change synonyms without having to close and reopen the index but instead use the reload API.
Updatable synonyms restrict the analyzer they are used in to be only used at search time, but you set it as an index analyzer in your "title" mapping. Instead you can use it as "search_analyzer" and define another one not doing the synonym expansion as the index analyzer.
The reason behind disallowing mutable synonym files etc... at index time is that you can end up with documents being analyzed in different ways, e.g. you index a document "fast car", later add a synonym "cat, automobile", then add another "red car" and search for "automobile". This search will return only the second document, which is very confusing and hard to understand from a user perspective. If instead you index without synonyms at index time, but your search for "automobile" get expanded to "car, automobile" at search time, you get the flexibility and match both documents.

Hope this helps!

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.