Custom Search analyzer

Hi Team,

I got stuck in very interesting issue.

I have implemented synonyms feature in my index, its working fine.

in my synonyms file, i have oil, lube,lubricate.

when I search with oil, Es is automatically searching for lube & lubricate,it's working as expected.

But the problem is when I search with oil filter term its hitting the document which contains lube filter as well I don't want this to happen is there any filter/analyzer which will search with the given words excluding its synonyms.

Here is the setting and mapping

"filter": {
"synonym": {
"type": "synonym",
"synonyms_path": "D:\MyElasticSearch\elasticsearch-1.5.2\config\synonymsnew.txt",
"ignore_case": "true"

"analyzer": {
"synonym": {
"filter": [
"tokenizer": "whitespace"

Here is my mapping

"BrandName": {
"type": "string",
"index_analyzer": "synonym",
"search_analyzer": "standard",
"fields": {
"raw": {
"type": "string"

And My search query is this

GET /_search
"query": {
"bool": {
"must": [
"query_string": {
"query": "oil filter",
"default_operator": "AND"


afaik, when you use a synonyms analyzer at index time, it "replace" in the analyzed field terms, so in the destination field when you index "oil", it puts "oil, lube,lubricate". So it's normal that you find the document when searching "lube".


yes exactly Xavier but when I search with oil filter it should search exactly oil filter not lube filter,

is there any way to sort this out.

According to your synonyms when you index "oil filter" or "lube filter", Elasticsearch stores "oil lube lubricate filter", so that's normal that when you search "oil filter" it match "lube filter"...

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