# How to combine prefix query with synonym filter in Elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-to-combine-prefix-query-with-synonym-filter-in-elasticsearch/294235>\
**Category:** Elasticsearch\
**Created:** [January 13, 2022, 5:59am UTC](https://discuss.elastic.co/t/how-to-combine-prefix-query-with-synonym-filter-in-elasticsearch/294235 "2022-01-13T05:59:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![learningmore](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@learningmore](https://discuss.elastic.co/u/learningmore)\
**Post date:** [January 13, 2022, 5:59am UTC](https://discuss.elastic.co/t/how-to-combine-prefix-query-with-synonym-filter-in-elasticsearch/294235/1 "2022-01-13T05:59:13Z")

</div>

I'm currently using Elasticsearch 7.16 and came across an issue.

Assume that we have the following data:

```auto
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):

```auto
rooster,chicken

```

The below **MATCH** query will return both `chicken` and `rooster`.

```auto
"query": {
    "match": {
      "animal": "chicken"
  }
}

```

But the below **PREFIX** query will only return `chicken`, but no `rooster`.

```auto
"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:

```auto
"filter": {
	"synonyms_animal": {
		"type": "synonym_graph",
		"synonyms_path": "synonyms_animal.txt",
		"updateable": "true"
	}
}

```

```auto
"analyzer": {
	"custom_synonyms": {
		"filter": [
			"lowercase",
			"synonyms_animal"
		],
		"tokenizer": "whitespace"
	}
}

```

This is my mapping properties section:

```auto
"animal": {
	"type": "text",
	"analyzer": "some_custom_index_analyzer",
	"search_analyzer": "custom_synonyms"
}

```

---

<div class="post-metadata">

**Author:** ![susanwray](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/susanwray/32/100259_2.png) [@susanwray](https://discuss.elastic.co/u/susanwray)\
**Post date:** [January 13, 2022, 7:26am UTC](https://discuss.elastic.co/t/how-to-combine-prefix-query-with-synonym-filter-in-elasticsearch/294235/2 "2022-01-13T07:26:18Z")

</div>

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](https://www.theacademicpapers.co.uk/dissertation-writing-services-uk.php)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 10, 2022, 7:26am UTC](https://discuss.elastic.co/t/how-to-combine-prefix-query-with-synonym-filter-in-elasticsearch/294235/3 "2022-02-10T07:26:23Z")

</div>

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