# Synonym filter behavior for single word / multi words

**URL:** <https://discuss.elastic.co/t/synonym-filter-behavior-for-single-word-multi-words/17858>\
**Category:** Elasticsearch\
**Created:** [June 2, 2014, 1:34pm UTC](https://discuss.elastic.co/t/synonym-filter-behavior-for-single-word-multi-words/17858 "2014-06-02T13:34:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bernhardt\_Scherer](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@Bernhardt\_Scherer](https://discuss.elastic.co/u/Bernhardt_Scherer)\
**Post date:** [June 2, 2014, 1:34pm UTC](https://discuss.elastic.co/t/synonym-filter-behavior-for-single-word-multi-words/17858/1 "2014-06-02T13:34:30Z")

</div>

Hello there,

I am currently trying out the synonym filter. Here are my settings:

"settings": {  
"analysis": {  
"filter": {  
"nGram\_filter": {  
"type": "nGram",  
"min\_gram": 2,  
"max\_gram": 15  
},  
"synonym": {  
"type": "synonym",  
"synonyms\_path" : "analysis/synonym.txt",  
"ignore\_case": true,  
"expand": true  
}  
},  
"analyzer": {  
"synonym\_analyzer": {  
"type":"custom",  
"tokenizer": "whitespace",  
"filter": [  
"synonym",  
"lowercase",  
"asciifolding"  
]  
}  
}  
}  
}

In the synonym.txt file I have the following line:

Inbus, Innensechskant, Imbus

When I test the analyzer, I get the following results (output is  
reformatted for ease of reading). It seems the synonym analyzer only does  
its job when the "synonym" word is surrounded by other words

localhost:9200/index\_v1/\_analyze?analyzer=synonym\_analyzer  
--input: 'Inbus'  
--output: inbus

localhost:9200/index\_v1/\_analyze?analyzer=synonym\_analyzer  
--input: 'Der Inbus'  
--output: 'der inbus'

localhost:9200/index\_v1/\_analyze?analyzer=synonym\_analyzer  
--input: 'Der Inbus ist'  
--output: 'der inbus innensechskant imbus ist'

Could anyone please explain why it behaves like this and how to implement  
this correctly?

Big thanks in advance!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c843106e-be78-4d4c-9101-2c73720b4062%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c843106e-be78-4d4c-9101-2c73720b4062%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![ElasticSearch\_Users\_](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@ElasticSearch\_Users\_](https://discuss.elastic.co/u/ElasticSearch_Users_)\
**Post date:** [June 2, 2014, 7:59pm UTC](https://discuss.elastic.co/t/synonym-filter-behavior-for-single-word-multi-words/17858/2 "2014-06-02T19:59:43Z")

</div>

It seems to work fine for me (ES 1.2). Can you please post an full  
reproducible sequence of commands that I can execute to try?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/bc463d08-873f-4a25-983a-7a1c89c42cbc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bc463d08-873f-4a25-983a-7a1c89c42cbc%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![ElasticSearch\_Users\_](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@ElasticSearch\_Users\_](https://discuss.elastic.co/u/ElasticSearch_Users_)\
**Post date:** [June 2, 2014, 8:01pm UTC](https://discuss.elastic.co/t/synonym-filter-behavior-for-single-word-multi-words/17858/3 "2014-06-02T20:01:13Z")

</div>

What I mean by working:

Input: Inbus  
Output:

{  
"tokens" : [ {  
"token" : "inbus",  
"start\_offset" : 0,  
"end\_offset" : 5,  
"type" : "SYNONYM",  
"position" : 1  
}, {  
"token" : "innensechskant",  
"start\_offset" : 0,  
"end\_offset" : 5,  
"type" : "SYNONYM",  
"position" : 1  
}, {  
"token" : "imbus",  
"start\_offset" : 0,  
"end\_offset" : 5,  
"type" : "SYNONYM",  
"position" : 1  
} ]  
}

Input: Der Inbus  
Output:

{  
"tokens" : [ {  
"token" : "der",  
"start\_offset" : 0,  
"end\_offset" : 3,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "inbus",  
"start\_offset" : 4,  
"end\_offset" : 9,  
"type" : "SYNONYM",  
"position" : 2  
}, {  
"token" : "innensechskant",  
"start\_offset" : 4,  
"end\_offset" : 9,  
"type" : "SYNONYM",  
"position" : 2  
}, {  
"token" : "imbus",  
"start\_offset" : 4,  
"end\_offset" : 9,  
"type" : "SYNONYM",  
"position" : 2  
} ]  
}

Input: Der Inbus ist  
Output:

{  
"tokens" : [ {  
"token" : "der",  
"start\_offset" : 0,  
"end\_offset" : 3,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "inbus",  
"start\_offset" : 4,  
"end\_offset" : 9,  
"type" : "SYNONYM",  
"position" : 2  
}, {  
"token" : "innensechskant",  
"start\_offset" : 4,  
"end\_offset" : 9,  
"type" : "SYNONYM",  
"position" : 2  
}, {  
"token" : "imbus",  
"start\_offset" : 4,  
"end\_offset" : 9,  
"type" : "SYNONYM",  
"position" : 2  
}, {  
"token" : "ist",  
"start\_offset" : 10,  
"end\_offset" : 13,  
"type" : "word",  
"position" : 3  
} ]  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d49aaaab-98d5-4d7a-aa16-63a77d0d0fab%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d49aaaab-98d5-4d7a-aa16-63a77d0d0fab%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Bernhardt\_Scherer](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@Bernhardt\_Scherer](https://discuss.elastic.co/u/Bernhardt_Scherer)\
**Post date:** [June 3, 2014, 12:19pm UTC](https://discuss.elastic.co/t/synonym-filter-behavior-for-single-word-multi-words/17858/4 "2014-06-03T12:19:14Z")

</div>

Hey Binh,

thanks for your reply!

I tried the following:

1. 

POST localhost:9200/index\_v2/

{  
"settings": {  
"analysis": {  
"filter": {  
"synonym": {  
"type": "synonym",  
"synonyms": [  
"Schraubenzieher, Schraubendreher",  
"Inbus, Innensechskant, Imbus, Innen-6-Kant",  
"Innensechskantschlüssel, Inbusschlüssel",  
"Bauhelm, Schutzhelm"  
],  
"ignore\_case": true,  
"expand": true  
}  
},  
"analyzer": {  
"synonym\_analyzer": {  
"type":"custom",  
"tokenizer": "whitespace",  
"filter": [  
"synonym",  
"lowercase",  
"asciifolding"  
]  
}  
}  
}  
}  
}

1. 

POST localhost:9200/index\_v2/\_analyze?analyzer=synonym\_analyzer  
'Inbus'

Output:  
{  
"tokens": [  
{  
"token": "'inbus'",  
"start\_offset": 0,  
"end\_offset": 7,  
"type": "word",  
"position": 1  
}  
]  
}

1. 

POST localhost:9200/index\_v2/\_analyze?analyzer=synonym\_analyzer  
'Inbus'

Output:  
{  
"tokens": [  
{  
"token": "'der",  
"start\_offset": 0,  
"end\_offset": 4,  
"type": "word",  
"position": 1  
},  
{  
"token": "inbus",  
"start\_offset": 5,  
"end\_offset": 10,  
"type": "SYNONYM",  
"position": 2  
},  
{  
"token": "innensechskant",  
"start\_offset": 5,  
"end\_offset": 10,  
"type": "SYNONYM",  
"position": 2  
},  
{  
"token": "imbus",  
"start\_offset": 5,  
"end\_offset": 10,  
"type": "SYNONYM",  
"position": 2  
},  
{  
"token": "innen-6-kant",  
"start\_offset": 5,  
"end\_offset": 10,  
"type": "SYNONYM",  
"position": 2  
},  
{  
"token": "ist'",  
"start\_offset": 11,  
"end\_offset": 15,  
"type": "word",  
"position": 3  
}  
]  
}

I have changed to 1.0.1 but the behavior was the same on 1.2..

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f57e83e1-8af1-4102-8083-b23532932ac1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f57e83e1-8af1-4102-8083-b23532932ac1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Bernhardt\_Scherer](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@Bernhardt\_Scherer](https://discuss.elastic.co/u/Bernhardt_Scherer)\
**Post date:** [June 3, 2014, 12:20pm UTC](https://discuss.elastic.co/t/synonym-filter-behavior-for-single-word-multi-words/17858/5 "2014-06-03T12:20:23Z")

</div>

> Hey Binh,
> 
> thanks for your reply!
> 
> I tried the following:
> 
> 1. 
> 
> POST localhost:9200/index\_v2/
> 
> {  
> "settings": {  
> "analysis": {  
> "filter": {  
> "synonym": {  
> "type": "synonym",  
> "synonyms": [  
> "Schraubenzieher, Schraubendreher",  
> "Inbus, Innensechskant, Imbus, Innen-6-Kant",  
> "Innensechskantschlüssel, Inbusschlüssel",  
> "Bauhelm, Schutzhelm"  
> ],  
> "ignore\_case": true,  
> "expand": true  
> }  
> },  
> "analyzer": {  
> "synonym\_analyzer": {  
> "type":"custom",  
> "tokenizer": "whitespace",  
> "filter": [  
> "synonym",  
> "lowercase",  
> "asciifolding"  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> 1. 
> 
> POST localhost:9200/index\_v2/\_analyze?analyzer=synonym\_analyzer  
> 'Inbus'
> 
> Output:  
> {  
> "tokens": [  
> {  
> "token": "'inbus'",  
> "start\_offset": 0,  
> "end\_offset": 7,  
> "type": "word",  
> "position": 1  
> }  
> ]  
> }
> 
> 1. 
> 
> POST localhost:9200/index\_v2/\_analyze?analyzer=synonym\_analyzer  
> 'Der Inbus ist'
> 
> Output:  
> {  
> "tokens": [  
> {  
> "token": "'der",  
> "start\_offset": 0,  
> "end\_offset": 4,  
> "type": "word",  
> "position": 1  
> },  
> {  
> "token": "inbus",  
> "start\_offset": 5,  
> "end\_offset": 10,  
> "type": "SYNONYM",  
> "position": 2  
> },  
> {  
> "token": "innensechskant",  
> "start\_offset": 5,  
> "end\_offset": 10,  
> "type": "SYNONYM",  
> "position": 2  
> },  
> {  
> "token": "imbus",  
> "start\_offset": 5,  
> "end\_offset": 10,  
> "type": "SYNONYM",  
> "position": 2  
> },  
> {  
> "token": "innen-6-kant",  
> "start\_offset": 5,  
> "end\_offset": 10,  
> "type": "SYNONYM",  
> "position": 2  
> },  
> {  
> "token": "ist'",  
> "start\_offset": 11,  
> "end\_offset": 15,  
> "type": "word",  
> "position": 3  
> }  
> ]  
> }
> 
> I have changed to 1.0.1 but the behavior was the same on 1.2..

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/18c6aa41-12b7-4301-8661-53162454f158%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/18c6aa41-12b7-4301-8661-53162454f158%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:25am UTC](https://discuss.elastic.co/t/synonym-filter-behavior-for-single-word-multi-words/17858/6 "2017-07-06T01:25:00Z")

</div>


