# Specifying the search analyzer for a multi\_match query

**URL:** <https://discuss.elastic.co/t/specifying-the-search-analyzer-for-a-multi-match-query/14989>\
**Category:** Elasticsearch\
**Created:** [December 22, 2013, 6:22am UTC](https://discuss.elastic.co/t/specifying-the-search-analyzer-for-a-multi-match-query/14989 "2013-12-22T06:22:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Igal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igal/32/1119_2.png) [@Igal](https://discuss.elastic.co/u/Igal)\
**Post date:** [December 22, 2013, 6:22am UTC](https://discuss.elastic.co/t/specifying-the-search-analyzer-for-a-multi-match-query/14989/1 "2013-12-22T06:22:57Z")

</div>

hi,

I've defined a custom analyzer that does stemming (kstem) and synonym  
expansion, called "synonym\_analyzer".

I've set it as the default analyzer for the index, i.e.  
settings.analysis.analyzer.default.type: "synonym\_analyzer"

I've also set it explicitly as the analyzer for the "title" and  
"description" fields, which are the fields that I am searching on.

now I'm running a multi\_match query on the "title" and "description"  
fields, like so:

GET /\_search  
{  
"query": {  
"multi\_match" : {  
"query" : "red widgets"  
,"fields" : ["title^3", "description"]  
,"operator": "and"  
}  
}  
}

I expect the search results for "red widget" and "red widgets" to be  
identical, since the "synonym\_analyzer" does stemming, but instead I get  
slightly different results (2 more results on the singular term vs. the  
plural term).

testing the analyzer with

GET /myindex/\_analyzer?text=Widgets returns "widgets"

```
 while

```

GET /myindex/\_analyzer?text=Widgets&analyzer=synonym\_analyzer returns  
"widget"

so it looks like the default analyzer is not the synonym\_analyzer as I  
expect it to be. what am I doing wrong? or how can I specify the  
analyzer to use in the query so that the search terms are stemmed?

TIA,

Igal

--  
Igal Sapir  
Railo Core Developer  
[http://getRailo.org/](http://getRailo.org/)

--  
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/52B68541.9010401%40getrailo.org](https://groups.google.com/d/msgid/elasticsearch/52B68541.9010401%40getrailo.org).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)\
**Post date:** [December 22, 2013, 9:25am UTC](https://discuss.elastic.co/t/specifying-the-search-analyzer-for-a-multi-match-query/14989/2 "2013-12-22T09:25:50Z")

</div>

Obviously it has something to do with the text you are indexing and the  
shape of the real queries you are using. You have 2 options - either use  
Explain to get back an explanation for why this happens and figure out what  
happens from there, or isolate this to a unit test and go from there.

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)

On Sun, Dec 22, 2013 at 8:22 AM, Igal @ [getRailo.org](http://getRailo.org) [igal@getrailo.org](mailto:igal@getrailo.org)wrote:

> hi,
> 
> I've defined a custom analyzer that does stemming (kstem) and synonym  
> expansion, called "synonym\_analyzer".
> 
> I've set it as the default analyzer for the index, i.e.  
> settings.analysis.analyzer.default.type: "synonym\_analyzer"
> 
> I've also set it explicitly as the analyzer for the "title" and  
> "description" fields, which are the fields that I am searching on.
> 
> now I'm running a multi\_match query on the "title" and "description"  
> fields, like so:
> 
> GET /\_search  
> {  
> "query": {  
> "multi\_match" : {  
> "query" : "red widgets"  
> ,"fields" : ["title^3", "description"]  
> ,"operator": "and"  
> }  
> }  
> }
> 
> I expect the search results for "red widget" and "red widgets" to be  
> identical, since the "synonym\_analyzer" does stemming, but instead I get  
> slightly different results (2 more results on the singular term vs. the  
> plural term).
> 
> testing the analyzer with
> 
> GET /myindex/\_analyzer?text=Widgets returns "widgets"
> 
> ```
> while
> 
> ```
> 
> GET /myindex/\_analyzer?text=Widgets&analyzer=synonym\_analyzer returns  
> "widget"
> 
> so it looks like the default analyzer is not the synonym\_analyzer as I  
> expect it to be. what am I doing wrong? or how can I specify the analyzer  
> to use in the query so that the search terms are stemmed?
> 
> TIA,
> 
> Igal
> 
> --  
> Igal Sapir  
> Railo Core Developer  
> [http://getRailo.org/](http://getRailo.org/)
> 
> --  
> 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/](https://groups.google.com/d/)  
> msgid/elasticsearch/52B68541.9010401%[40getrailo.org](http://40getrailo.org).  
> 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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAHTr4Zt3mEugSgh04xGnqi6V9sHfo1EM%3D%2Bi6k0P6%2BMjgQz2Vsg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4Zt3mEugSgh04xGnqi6V9sHfo1EM%3D%2Bi6k0P6%2BMjgQz2Vsg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Igal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igal/32/1119_2.png) [@Igal](https://discuss.elastic.co/u/Igal)\
**Post date:** [December 22, 2013, 9:10pm UTC](https://discuss.elastic.co/t/specifying-the-search-analyzer-for-a-multi-match-query/14989/3 "2013-12-22T21:10:48Z")

</div>

Thanks Itamar, I see the problem now. Apparently when I tried to create  
the index it was failing and I wasn't seeing the error message.

What I tried to do is set a _custom analyzer_ as the default by only  
specifying the name, e.g.

{  
"settings" : {  
"analysis" : {  
"analyzer" : {

```
     "default": { "type": "*synonym_analyzer*" }

    ,"*synonym_analyzer*": {

      "type" : "custom",
      "tokenizer" : "whitespace",
      "filter" : [ "standard", "lowercase", "english_stemmer", 

```

"synonyms\_site" ]  
}  
}

apparently duplicating the settings from synonym\_analyzer to default works.  
I was under the impression that I would not need to duplicate the settings.

Igal

On Sunday, December 22, 2013 1:25:50 AM UTC-8, Itamar Syn-Hershko wrote:

> Obviously it has something to do with the text you are indexing and the  
> shape of the real queries you are using. You have 2 options - either use  
> Explain to get back an explanation for why this happens and figure out what  
> happens from there, or isolate this to a unit test and go from there.
> 
> --
> 
> Itamar Syn-Hershko  
> [http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
> Freelance Developer & Consultant  
> Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)
> 
> On Sun, Dec 22, 2013 at 8:22 AM, Igal @ [getRailo.org](http://getRailo.org) \<[ig...@getrailo.org](mailto:ig...@getrailo.org)\<javascript:\>
> 
> > wrote:
> 
> > hi,
> > 
> > I've defined a custom analyzer that does stemming (kstem) and synonym  
> > expansion, called "synonym\_analyzer".
> > 
> > I've set it as the default analyzer for the index, i.e.  
> > settings.analysis.analyzer.default.type: "synonym\_analyzer"
> > 
> > I've also set it explicitly as the analyzer for the "title" and  
> > "description" fields, which are the fields that I am searching on.
> > 
> > now I'm running a multi\_match query on the "title" and "description"  
> > fields, like so:
> > 
> > GET /\_search  
> > {  
> > "query": {  
> > "multi\_match" : {  
> > "query" : "red widgets"  
> > ,"fields" : ["title^3", "description"]  
> > ,"operator": "and"  
> > }  
> > }  
> > }
> > 
> > I expect the search results for "red widget" and "red widgets" to be  
> > identical, since the "synonym\_analyzer" does stemming, but instead I get  
> > slightly different results (2 more results on the singular term vs. the  
> > plural term).
> > 
> > testing the analyzer with
> > 
> > GET /myindex/\_analyzer?text=Widgets returns "widgets"
> > 
> > ```
> > while
> > 
> > ```
> > 
> > GET /myindex/\_analyzer?text=Widgets&analyzer=synonym\_analyzer returns  
> > "widget"
> > 
> > so it looks like the default analyzer is not the synonym\_analyzer as I  
> > expect it to be. what am I doing wrong? or how can I specify the analyzer  
> > to use in the query so that the search terms are stemmed?
> > 
> > TIA,
> > 
> > Igal
> > 
> > --  
> > Igal Sapir  
> > Railo Core Developer  
> > [http://getRailo.org/](http://getRailo.org/)
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > msgid/elasticsearch/52B68541.9010401%[40getrailo.org](http://40getrailo.org).  
> > 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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9b3ac211-e268-458c-9794-29bc33c7cf72%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9b3ac211-e268-458c-9794-29bc33c7cf72%40googlegroups.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, 1:59am UTC](https://discuss.elastic.co/t/specifying-the-search-analyzer-for-a-multi-match-query/14989/4 "2017-07-06T01:59:42Z")

</div>


