How to combine prefix query with synonym filter in Elasticsearch?

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"
}

The index_prefixes boundary empowers the ordering of term prefixes to accelerate prefix look. It acknowledges this setting: min_chars. The base prefix length to file. It should be more prominent than 0 and defaults to 2.
Custom Dissertation Writing Service UK

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