# Synonym analyzer not picked up as search\_analyzer for field

**URL:** <https://discuss.elastic.co/t/synonym-analyzer-not-picked-up-as-search-analyzer-for-field/17192>\
**Category:** Elasticsearch\
**Created:** [April 25, 2014, 8:43am UTC](https://discuss.elastic.co/t/synonym-analyzer-not-picked-up-as-search-analyzer-for-field/17192 "2014-04-25T08:43:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas\_Wikell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andreas_wikell/32/1617_2.png) [@Andreas\_Wikell](https://discuss.elastic.co/u/Andreas_Wikell)\
**Post date:** [April 25, 2014, 8:43am UTC](https://discuss.elastic.co/t/synonym-analyzer-not-picked-up-as-search-analyzer-for-field/17192/1 "2014-04-25T08:43:23Z")

</div>

I'm using ES 1.0.0. I'm storing products with a "color" string field which  
is just a single string representing a color (e.g. "white" or "purple"). I  
want queries for variations of these color names to return results, so I've  
defined the following analyzer and set it to be used as the search\_analyzer  
for the color field:

_Settings_

{  
"analysis": {  
"analyzer": {

```
             "color_synonyms" : {

                      "tokenizer" : "whitespace",

                       "filter" : ["synonyms"]

           }

         },

        "filter" : {

              "synonyms" : {

                    "type" : "synonym",

                       "synonyms_path" : "analysis/synonyms.txt",

                        "ignore_case" : true

              }

         }

 }

```

}

_Mapping:_  
"color" : {

```
       "type" : "string",

       "index_analyzer" : "keyword",

       "search_analyzer" : "color_synonyms"

     },

```

I've tested that the analyzer works correctly:

> curl -XGET 'localhost:9200/products/\_analyze?analyzer=color\_synonyms' -d  
> 'purple'

> {"tokens":[{"token":"lila","start\_offset":0,"end\_offset":6,"type":"SYNONYM"  
> ,"position":1},{"token":"purpur","start\_offset":0,"end\_offset":6,"type":  
> "SYNONYM","position":1},{"token":"purple","start\_offset":0,"end\_offset":6,  
> "type":"SYNONYM","position":1}]}

But it seems it doesn't use the analyzer for the color field:

> curl -XGET 'localhost:9200/products/\_analyze?field=Product.color' -d  
> 'purple'

> {"tokens":[{"token":"purple","start\_offset":0,"end\_offset":6,"type":"word"  
> ,"position":1}]}

Am I missing something obvious or doing something wrong?

--  
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/fa5b8282-019b-434a-94b4-3a60eec7d893%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fa5b8282-019b-434a-94b4-3a60eec7d893%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [April 25, 2014, 11:28pm UTC](https://discuss.elastic.co/t/synonym-analyzer-not-picked-up-as-search-analyzer-for-field/17192/2 "2014-04-25T23:28:07Z")

</div>

The index analyzer is used when the field is specific in the analyze  
request.

[https://github.com/elasticsearch/elasticsearch/blob/1.x/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java#L130](https://github.com/elasticsearch/elasticsearch/blob/1.x/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java#L130)

--  
Ivan

On Fri, Apr 25, 2014 at 1:43 AM, Andreas Wikell \<andreas.wikell@schibsted.se

> wrote:

> I'm using ES 1.0.0. I'm storing products with a "color" string field which  
> is just a single string representing a color (e.g. "white" or "purple"). I  
> want queries for variations of these color names to return results, so I've  
> defined the following analyzer and set it to be used as the search\_analyzer  
> for the color field:
> 
> _Settings_
> 
> {  
> "analysis": {  
> "analyzer": {
> 
> ```
> "color_synonyms" : {
> 
> "tokenizer" : "whitespace",
> 
> "filter" : ["synonyms"]
> 
> }
> 
> },
> 
> "filter" : {
> 
> "synonyms" : {
> 
> "type" : "synonym",
> 
> "synonyms_path" : "analysis/synonyms.txt",
> 
> "ignore_case" : true
> 
> }
> 
> }
> 
> }
> 
> ```
> 
> }
> 
> _Mapping:_  
> "color" : {
> 
> ```
> "type" : "string",
> 
> "index_analyzer" : "keyword",
> 
> "search_analyzer" : "color_synonyms"
> 
> },
> 
> ```
> 
> I've tested that the analyzer works correctly:
> 
> > curl -XGET 'localhost:9200/products/\_analyze?analyzer=color\_synonyms' -d  
> > 'purple'
> 
> > {"tokens":[{"token":"lila","start\_offset":0,"end\_offset":6,"type":  
> > "SYNONYM","position":1},{"token":"purpur","start\_offset":0,"end\_offset":6,  
> > "type":"SYNONYM","position":1},{"token":"purple","start\_offset":0,  
> > "end\_offset":6,"type":"SYNONYM","position":1}]}
> 
> But it seems it doesn't use the analyzer for the color field:
> 
> > curl -XGET 'localhost:9200/products/\_analyze?field=Product.color' -d  
> > 'purple'
> 
> > {"tokens":[{"token":"purple","start\_offset":0,"end\_offset":6,"type":  
> > "word","position":1}]}
> 
> Am I missing something obvious or doing something wrong?
> 
> --  
> 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/fa5b8282-019b-434a-94b4-3a60eec7d893%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fa5b8282-019b-434a-94b4-3a60eec7d893%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/fa5b8282-019b-434a-94b4-3a60eec7d893%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/fa5b8282-019b-434a-94b4-3a60eec7d893%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CALY%3DcQA-1ddp6N\_N9CT37vCejH4qdOSkGr%3DYkkym-Q5JBd8EXg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA-1ddp6N_N9CT37vCejH4qdOSkGr%3DYkkym-Q5JBd8EXg%40mail.gmail.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:33am UTC](https://discuss.elastic.co/t/synonym-analyzer-not-picked-up-as-search-analyzer-for-field/17192/3 "2017-07-06T01:33:25Z")

</div>


