Alibaba Cloud Elasticsearch allows you to use a filter to configure synonyms. The filter supports two synonym formats: Solr and WordNet.
Configuration example
PUT /test_index
{
"settings": {
"index" : {
"analysis" : {
"analyzer" : {
"synonym" : {
"tokenizer" : "whitespace",
"filter" : ["synonym"]
}
},
"filter" : {
"synonym" : {
"type" : "synonym",
"synonyms_path" : "analysis/synonym.txt",
"tokenizer" : "whitespace"
}
}
}
}
}
}
In this example, a synonym
filter that contains synonym dictionary file path analysis/synonym.txt
is configured in filter
. This path indicates the location of config. For more information about parameters,
see Synonym Token Filter in the open-source Elasticsearch documentation.
Solr synonyms
Configuration example:
# 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
You can also define synonyms in the filter, but you must use
synonyms
rather than synonyms_path
. The sample code is as follows:
PUT /test_index
{
"settings": {
"index" : {
"analysis" : {
"filter" : {
"synonym" : {
"type" : "synonym",
"synonyms" : [
"i-pod, i pod => ipod",
"begin, start"
]
}
}
}
}
}
}
Note We recommend that you use
synonyms_path
to define large synonym sets in the file.
WordNet synonyms
Configuration example:
PUT /test_index
{
"settings": {
"index" : {
"analysis" : {
"filter" : {
"synonym" : {
"type" : "synonym",
"format" : "wordnet",
"synonyms" : [
"s(100000001,1,'abstain',v,1,0).",
"s(100000001,2,'refrain',v,1,0).",
"s(100000001,3,'desist',v,1,0)."
]
}
}
}
}
}
}
This example uses synonyms
to define WordNet synonyms. You can also use synonyms_path
to define WordNet synonyms.