# Problem with synonym search

**URL:** <https://discuss.elastic.co/t/problem-with-synonym-search/8313>\
**Category:** Elasticsearch\
**Created:** [July 4, 2012, 1:38pm UTC](https://discuss.elastic.co/t/problem-with-synonym-search/8313 "2012-07-04T13:38:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![clotildeh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/clotildeh/32/2826_2.png) [@clotildeh](https://discuss.elastic.co/u/clotildeh)\
**Post date:** [July 4, 2012, 1:38pm UTC](https://discuss.elastic.co/t/problem-with-synonym-search/8313/1 "2012-07-04T13:38:20Z")

</div>

Hello,

I defined synonyms in my txt file : canapé, banquette, poof  
When I launch this command : curl -XGET '  
[http://127.0.0.1:9200/my\_index/\_analyze?pretty=1&text=poof&analyzer=default](http://127.0.0.1:9200/my_index/_analyze?pretty=1&text=poof&analyzer=default)',  
i have my synonyms :  
{  
"tokens" : [ {  
"token" : "canapé",  
"start\_offset" : 0,  
"end\_offset" : 4,  
"type" : "SYNONYM",  
"position" : 1  
}, {  
"token" : "banquette",  
"start\_offset" : 0,  
"end\_offset" : 4,  
"type" : "SYNONYM",  
"position" : 1  
}, {  
"token" : "poof",  
"start\_offset" : 0,  
"end\_offset" : 4,  
"type" : "SYNONYM",  
"position" : 1  
} ]  
}

But, when I do a research, I only have the documents that contain the word  
"canapé". I don't have the documents that contain the words "poof" and  
"banquette" (3 hits over 5)

curl -XGET '[http://127.0.0.1:9200/testavecparam/products/\_search?pretty=1](http://127.0.0.1:9200/testavecparam/products/_search?pretty=1)'  
-d '  
{  
"query" : {  
"text" : {  
"products.designation" : {  
"query" : "canape",  
"analyzer" : "default"  
}  
}  
}

}  
'

My configuration :  
"settings" : {  
"analysis" : {  
"analyzer" : {  
"default" : {  
"type" : "custom",  
"tokenizer" : "standard"  
"filter" : [  
"standard",  
"lowercase",  
"myStemmer",  
"asciifolding",  
"mySynonym"  
],

```
        }
     }
     "filter" : {
        "myStemmer" : {
           "type" : "stemmer",
           "language" : "light_french"
        }
        "mySynonym" : {
           "type" : "synonym",
           "synonyms_path" : "analysis/synonym.txt"
        }
     },
  }

```

}

Is there any problem with my configuration?

Thanks for your answers

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [July 5, 2012, 7:41am UTC](https://discuss.elastic.co/t/problem-with-synonym-search/8313/2 "2012-07-05T07:41:16Z")

</div>

Hi,

would you mind preparing complete curl recreation?  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/) (note you can use gist instead of  
pasting it into mali body, it is more practical)  
This typically helps a lot.

Regards,  
Lukas

On Wed, Jul 4, 2012 at 3:38 PM, clotildeh [c.hebert@novactive.com](mailto:c.hebert@novactive.com) wrote:

> Hello,
> 
> I defined synonyms in my txt file : canapé, banquette, poof  
> When I launch this command : curl -XGET '[http://127.0.0.1:9200/my\_](http://127.0.0.1:9200/my_)\*\*  
> index/\_analyze?pretty=1&text=\*\*poof&analyzer=default[http://127.0.0.1:9200/my\_index/\_analyze?pretty=1&text=poof&analyzer=default](http://127.0.0.1:9200/my_index/_analyze?pretty=1&text=poof&analyzer=default)',  
> i have my synonyms :  
> {  
> "tokens" : [ {  
> "token" : "canapé",  
> "start\_offset" : 0,  
> "end\_offset" : 4,  
> "type" : "SYNONYM",  
> "position" : 1  
> }, {  
> "token" : "banquette",  
> "start\_offset" : 0,  
> "end\_offset" : 4,  
> "type" : "SYNONYM",  
> "position" : 1  
> }, {  
> "token" : "poof",  
> "start\_offset" : 0,  
> "end\_offset" : 4,  
> "type" : "SYNONYM",  
> "position" : 1  
> } ]  
> }
> 
> But, when I do a research, I only have the documents that contain the word  
> "canapé". I don't have the documents that contain the words "poof" and  
> "banquette" (3 hits over 5)
> 
> curl -XGET '[http://127.0.0.1:9200/\*\*testavecparam/products/\_](http://127.0.0.1:9200/**testavecparam/products/_)\*\*  
> search?pretty=1[http://127.0.0.1:9200/testavecparam/products/\_search?pretty=1](http://127.0.0.1:9200/testavecparam/products/_search?pretty=1)'  
> -d '  
> {  
> "query" : {  
> "text" : {  
> "products.designation" : {  
> "query" : "canape",  
> "analyzer" : "default"  
> }  
> }  
> }
> 
> }  
> '
> 
> My configuration :  
> "settings" : {  
> "analysis" : {  
> "analyzer" : {  
> "default" : {  
> "type" : "custom",  
> "tokenizer" : "standard"  
> "filter" : [  
> "standard",  
> "lowercase",  
> "myStemmer",  
> "asciifolding",  
> "mySynonym"  
> ],
> 
> ```
> }
> }
> "filter" : {
> "myStemmer" : {
> "type" : "stemmer",
> "language" : "light_french"
> }
> "mySynonym" : {
> "type" : "synonym",
> "synonyms_path" : "analysis/synonym.txt"
> }
> },
> }
> 
> ```
> 
> }
> 
> Is there any problem with my configuration?
> 
> Thanks for your answers

---

<div class="post-metadata">

**Author:** ![Andreas\_W](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Andreas\_W](https://discuss.elastic.co/u/Andreas_W)\
**Post date:** [July 5, 2012, 9:52am UTC](https://discuss.elastic.co/t/problem-with-synonym-search/8313/3 "2012-07-05T09:52:28Z")

</div>

Hi clotildeh,

One challenge with synonyms is how to combine it with the stemming filter.

If you first apply the stemming filter and the synonym filter afterwards,  
you need to have the stemmed version of the word in your synonym.txt.

I did it vice versa: I first apply the synonym filter and afterwards the  
stemming filter. This implies that I have to list all variants of a word in  
synonym.txt. (Which obviously is easier for English than for French.)

Hope this helps,  
Andreas

---

<div class="post-metadata">

**Author:** ![clotildeh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/clotildeh/32/2826_2.png) [@clotildeh](https://discuss.elastic.co/u/clotildeh)\
**Post date:** [July 6, 2012, 8:09am UTC](https://discuss.elastic.co/t/problem-with-synonym-search/8313/4 "2012-07-06T08:09:00Z")

</div>

Hi Andreas,

Thank you for your help.  
Indeed, we found that putting the synonym filter before the stemming filter  
was giving better results.

We still need to get how the filters intercacted to make sure that we match  
expected document.  
Thank you for your answer

Le jeudi 5 juillet 2012 11:52:28 UTC+2, Andreas W a écrit :

> Hi clotildeh,
> 
> One challenge with synonyms is how to combine it with the stemming filter.
> 
> If you first apply the stemming filter and the synonym filter afterwards,  
> you need to have the stemmed version of the word in your synonym.txt.
> 
> I did it vice versa: I first apply the synonym filter and afterwards the  
> stemming filter. This implies that I have to list all variants of a word in  
> synonym.txt. (Which obviously is easier for English than for French.)
> 
> Hope this helps,  
> Andreas

---

<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, 3:21am UTC](https://discuss.elastic.co/t/problem-with-synonym-search/8313/5 "2017-07-06T03:21:18Z")

</div>


