I'm currently using Elasticsearch 7.16 and came across an issue.
Assume that we have the following data:
horse
mouse
chicken
rooster
duck
cow
Let's assume the synonym file has the following entries (i.e. rooster
and chicken
are synonym with each other):
rooster,chicken
The below MATCH query will return both chicken
and rooster
.
"query": {
"match": {
"animal": "chicken"
}
}
But the below PREFIX query will only return chicken
, but no rooster
.
"query": {
"prefix": {
"animal": "chic"
}
}
What I wanted is for the user to enter just chic
and Elasticsearch will return both chicken
and rooster
.
Is there a way to combine a prefix search with synonym?
This is in my setting:
"filter": {
"synonyms_animal": {
"type": "synonym_graph",
"synonyms_path": "synonyms_animal.txt",
"updateable": "true"
}
}
"analyzer": {
"custom_synonyms": {
"filter": [
"lowercase",
"synonyms_animal"
],
"tokenizer": "whitespace"
}
}
This is my mapping properties section:
"animal": {
"type": "text",
"analyzer": "some_custom_index_analyzer",
"search_analyzer": "custom_synonyms"
}