# Using the synonyms while using the \_search "method"

**URL:** <https://discuss.elastic.co/t/using-the-synonyms-while-using-the--search-method/13933>\
**Category:** Elasticsearch\
**Created:** [October 13, 2013, 1:23pm UTC](https://discuss.elastic.co/t/using-the-synonyms-while-using-the--search-method/13933 "2013-10-13T13:23:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bruno\_ais](https://avatars.discourse-cdn.com/v4/letter/b/50afbb/32.png) [@bruno\_ais](https://discuss.elastic.co/u/bruno_ais)\
**Post date:** [October 13, 2013, 1:23pm UTC](https://discuss.elastic.co/t/using-the-synonyms-while-using-the--search-method/13933/1 "2013-10-13T13:23:15Z")

</div>

This is something I was unable to find out in the manual.  
I have made some synonyms but I was unable to make it work so that when I  
search for something those synonyms are used in the search and are added to  
the search parameters

For example, if I add some synonyms to the file and then use the \_analize  
API such that it includes the synonyms it find the synonyms properly but it  
does not give my any advice about how to replace them so I can't use that  
to enrich my search.  
How do I use the synonym system for searching?  
Here's an example of what I want:  
If I search for:  
"+random +string I wanted to +give"  
And string and sentence are synonyms, then it would search for:  
"+random +(string OR sentence) I wanted to +give" (or equivalent)

How do I do that?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [October 13, 2013, 1:41pm UTC](https://discuss.elastic.co/t/using-the-synonyms-while-using-the--search-method/13933/2 "2013-10-13T13:41:53Z")

</div>

The query method you describe is query expansion. Query expansion is the  
process of adding terms to a query before it is submitted for search.

Query expansion is not specific to Elasticsearch, it can be implemented in  
any search UI. Elasticsearch is expanding the index when using synonyms. As  
a result, the index is larger but synonyms are not required to be given in  
the query.

If you want query expansion, you could write a plugin for managing synonyms  
by your custom method.

Note that index expansion has advantages over query expansion. The  
searching is faster.

Jörg  
Am 13.10.2013 15:23 schrieb "bruno ais" [brunoaiss@gmail.com](mailto:brunoaiss@gmail.com):

> This is something I was unable to find out in the manual.  
> I have made some synonyms but I was unable to make it work so that when I  
> search for something those synonyms are used in the search and are added to  
> the search parameters
> 
> For example, if I add some synonyms to the file and then use the \_analize  
> API such that it includes the synonyms it find the synonyms properly but it  
> does not give my any advice about how to replace them so I can't use that  
> to enrich my search.  
> How do I use the synonym system for searching?  
> Here's an example of what I want:  
> If I search for:  
> "+random +string I wanted to +give"  
> And string and sentence are synonyms, then it would search for:  
> "+random +(string OR sentence) I wanted to +give" (or equivalent)
> 
> How do I do that?
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![bruno\_ais](https://avatars.discourse-cdn.com/v4/letter/b/50afbb/32.png) [@bruno\_ais](https://discuss.elastic.co/u/bruno_ais)\
**Post date:** [October 13, 2013, 9:19pm UTC](https://discuss.elastic.co/t/using-the-synonyms-while-using-the--search-method/13933/3 "2013-10-13T21:19:22Z")

</div>

Is there a way to request a reindex to elasticsearch when the synonyms  
are changed?

On 13-10-2013 14:41, [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:

> The query method you describe is query expansion. Query expansion is  
> the process of adding terms to a query before it is submitted for search.
> 
> Query expansion is not specific to Elasticsearch, it can be  
> implemented in any search UI. Elasticsearch is expanding the index  
> when using synonyms. As a result, the index is larger but synonyms are  
> not required to be given in the query.
> 
> If you want query expansion, you could write a plugin for managing  
> synonyms by your custom method.
> 
> Note that index expansion has advantages over query expansion. The  
> searching is faster.
> 
> Jörg
> 
> Am 13.10.2013 15:23 schrieb "bruno ais" \<[brunoaiss@gmail.com](mailto:brunoaiss@gmail.com)  
> [mailto:brunoaiss@gmail.com](mailto:brunoaiss@gmail.com)\>:
> 
> ```
> This is something I was unable to find out in the manual.
> I have made some synonyms but I was unable to make it work so that
> when I search for something those synonyms are used in the search
> and are added to the search parameters
> 
> For example, if I add some synonyms to the file and then use the
> _analize API such that it includes the synonyms it find the
> synonyms properly but it does not give my any advice about how to
> replace them so I can't use that to enrich my search.
> How do I use the synonym system for searching?
> Here's an example of what I want:
> If I search for:
> "+random +string I wanted to +give"
> And string and sentence are synonyms, then it would search for:
> "+random +(string OR sentence) I wanted to +give" (or equivalent)
> 
> How do I do that?
> -- 
> 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%2Bunsubscribe@googlegroups.com>.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> ```
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/UW4jL3IUXbs/unsubscribe](https://groups.google.com/d/topic/elasticsearch/UW4jL3IUXbs/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![bruno\_ais](https://avatars.discourse-cdn.com/v4/letter/b/50afbb/32.png) [@bruno\_ais](https://discuss.elastic.co/u/bruno_ais)\
**Post date:** [October 13, 2013, 9:47pm UTC](https://discuss.elastic.co/t/using-the-synonyms-while-using-the--search-method/13933/4 "2013-10-13T21:47:50Z")

</div>

Ok, I got it now.  
1st:  
It seems like it is not doing index expansion. When I start an index with a  
synonyms file and then I store some information in it, if I do a boolean  
query search it is not matching the synonyms.  
E.g. I have a synonym:  
aaafoo =\> aaabar

So I expect when there's aaafoo I get aaafoo and aaabar (both) indexed.  
When I search for aaafoo I don't get the result. (I also tried searching  
for aaabar and trying to get the aaafoo result to test it out).  
Could it be that I'm doing something wrong int he way?  
Query JSON:  
{  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"search.searched": "aaafoo"  
}  
}  
]  
}  
}  
}

By the way, Is there a way to request a reindex to elasticsearch when the  
synonyms are changed?

On Sunday, October 13, 2013 10:19:22 PM UTC+1, bruno ais wrote:

> On 13-10-2013 14:41, [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:
> 
> The query method you describe is query expansion. Query expansion is the  
> process of adding terms to a query before it is submitted for search.
> 
> Query expansion is not specific to Elasticsearch, it can be implemented in  
> any search UI. Elasticsearch is expanding the index when using synonyms. As  
> a result, the index is larger but synonyms are not required to be given in  
> the query.
> 
> If you want query expansion, you could write a plugin for managing  
> synonyms by your custom method.
> 
> Note that index expansion has advantages over query expansion. The  
> searching is faster.
> 
> Jörg  
> Am 13.10.2013 15:23 schrieb "bruno ais" [brunoaiss@gmail.com](mailto:brunoaiss@gmail.com):
> 
> > This is something I was unable to find out in the manual.  
> > I have made some synonyms but I was unable to make it work so that when I  
> > search for something those synonyms are used in the search and are added to  
> > the search parameters
> > 
> > For example, if I add some synonyms to the file and then use the \_analize  
> > API such that it includes the synonyms it find the synonyms properly but it  
> > does not give my any advice about how to replace them so I can't use that  
> > to enrich my search.  
> > How do I use the synonym system for searching?  
> > Here's an example of what I want:  
> > If I search for:  
> > "+random +string I wanted to +give"  
> > And string and sentence are synonyms, then it would search for:  
> > "+random +(string OR sentence) I wanted to +give" (or equivalent)
> > 
> > ## How do I do that?
> > 
> > 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).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/UW4jL3IUXbs/unsubscribe](https://groups.google.com/d/topic/elasticsearch/UW4jL3IUXbs/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 13, 2013, 10:02pm UTC](https://discuss.elastic.co/t/using-the-synonyms-while-using-the--search-method/13933/5 "2013-10-13T22:02:22Z")

</div>

You should use analyze API to understand what elasticsearch is doing behind the scene: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-analyze.html)

You will see what tokens produce your analyzer.

> By the way, Is there a way to request a reindex to elasticsearch when the synonyms are changed?  
> You have to reindex yourself.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 13 oct. 2013 à 23:47, bruno ais [brunoaiss@gmail.com](mailto:brunoaiss@gmail.com) a écrit :

Ok, I got it now.  
1st:  
It seems like it is not doing index expansion. When I start an index with a synonyms file and then I store some information in it, if I do a boolean query search it is not matching the synonyms.  
E.g. I have a synonym:  
aaafoo =\> aaabar

So I expect when there's aaafoo I get aaafoo and aaabar (both) indexed.  
When I search for aaafoo I don't get the result. (I also tried searching for aaabar and trying to get the aaafoo result to test it out).  
Could it be that I'm doing something wrong int he way?  
Query JSON:  
{  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"search.searched": "aaafoo"  
}  
}  
]  
}  
}  
}

By the way, Is there a way to request a reindex to elasticsearch when the synonyms are changed?

> On Sunday, October 13, 2013 10:19:22 PM UTC+1, bruno ais wrote:
> 
> > On 13-10-2013 14:41, [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:  
> > The query method you describe is query expansion. Query expansion is the process of adding terms to a query before it is submitted for search.
> > 
> > Query expansion is not specific to Elasticsearch, it can be implemented in any search UI. Elasticsearch is expanding the index when using synonyms. As a result, the index is larger but synonyms are not required to be given in the query.
> > 
> > If you want query expansion, you could write a plugin for managing synonyms by your custom method.
> > 
> > Note that index expansion has advantages over query expansion. The searching is faster.
> > 
> > Jörg
> > 
> > Am 13.10.2013 15:23 schrieb "bruno ais" [brunoaiss@gmail.com](mailto:brunoaiss@gmail.com):
> > 
> > > This is something I was unable to find out in the manual.  
> > > I have made some synonyms but I was unable to make it work so that when I search for something those synonyms are used in the search and are added to the search parameters
> > > 
> > > For example, if I add some synonyms to the file and then use the \_analize API such that it includes the synonyms it find the synonyms properly but it does not give my any advice about how to replace them so I can't use that to enrich my search.  
> > > How do I use the synonym system for searching?  
> > > Here's an example of what I want:  
> > > If I search for:  
> > > "+random +string I wanted to +give"  
> > > And string and sentence are synonyms, then it would search for:  
> > > "+random +(string OR sentence) I wanted to +give" (or equivalent)
> > > 
> > > ## How do I do that?
> > > 
> > > 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).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).  
> > > --  
> > > You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/UW4jL3IUXbs/unsubscribe](https://groups.google.com/d/topic/elasticsearch/UW4jL3IUXbs/unsubscribe).  
> > > To unsubscribe from this group and all its topics, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [October 13, 2013, 11:43pm UTC](https://discuss.elastic.co/t/using-the-synonyms-while-using-the--search-method/13933/6 "2013-10-13T23:43:23Z")

</div>

Please post a sequence of your commands so it can be reproduced, it is not  
easy to find out what you are working on.

You have illustrated a "term" search which is probably the reason for  
missed hits because normally an analyzer is used, for this, a "match" query  
is preferred.

For a working synonym example and a demonstration of index expansion, see

> <https://gist.github.com/jprante/6968540>

Jörg

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![bruno\_ais](https://avatars.discourse-cdn.com/v4/letter/b/50afbb/32.png) [@bruno\_ais](https://discuss.elastic.co/u/bruno_ais)\
**Post date:** [October 14, 2013, 8:29am UTC](https://discuss.elastic.co/t/using-the-synonyms-while-using-the--search-method/13933/7 "2013-10-14T08:29:08Z")

</div>

Thank you Jörg Prante.  
Your example has shown me what I was doing wrong.

Also, sorry you two. I forgot to make you an example but anyway, my case  
was quite simple and you were able to show me my mistake with the example.  
Thank you

On Monday, October 14, 2013 12:43:23 AM UTC+1, Jörg Prante wrote:

> Please post a sequence of your commands so it can be reproduced, it is not  
> easy to find out what you are working on.
> 
> You have illustrated a "term" search which is probably the reason for  
> missed hits because normally an analyzer is used, for this, a "match" query  
> is preferred.
> 
> For a working synonym example and a demonstration of index expansion, see  
> [Synonym example with Elasticsearch · GitHub](https://gist.github.com/jprante/6968540)
> 
> Jörg

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:12am UTC](https://discuss.elastic.co/t/using-the-synonyms-while-using-the--search-method/13933/8 "2017-07-06T02:12:38Z")

</div>


