# Search query doesn't use custom analyzer

**URL:** <https://discuss.elastic.co/t/search-query-doesnt-use-custom-analyzer/27075>\
**Category:** Elasticsearch\
**Created:** [August 8, 2015, 7:34am UTC](https://discuss.elastic.co/t/search-query-doesnt-use-custom-analyzer/27075 "2015-08-08T07:34:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tivak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tivak/32/3610_2.png) [@Tivak](https://discuss.elastic.co/u/Tivak)\
**Post date:** [August 8, 2015, 7:34am UTC](https://discuss.elastic.co/t/search-query-doesnt-use-custom-analyzer/27075/1 "2015-08-08T07:34:31Z")

</div>

I have a problem. Halp me please.  
See the queries below

created new index with custom analyzer

```
PUT test
{
    "mappings": {
        "test": {
            "_all": {
               "analyzer": "testAnalyzer"
            },
            "properties": {
                "name": {
                  "type": "string",
                  "analyzer": "testAnalyzer"
                }
            }
        }
    }, 
    "settings": {
        "analysis": {
            "filter": {
                "testsyn": {
                     "type": "synonym",
                     "synonyms": [
                        "test test => test_test"
                     ]
                }
            },
            "analyzer": {
                "testAnalyzer": {
                     "filter": [
                        "lowercase",
                        "testsyn"
                     ],
                     "type": "custom",
                     "tokenizer": "standard"
                }
            }
        }
    }
}

```

Add data to index

```
PUT test/test/1
{
    "name": "test"
}

PUT test/test/2
{
    "name": "test test"
}

```

Check data and custom analyzer

```
POST test/test/_search
{
    "query": {
        "match_all": {}
    }
}

GET test/_analyze?analyzer=testAnalyzer&text=test test

```

Check query\_string, we can view that custom analyzer not use

```
POST test/test/_search
{
    "explain": true, 
    "query": {
        "query_string": {
           "default_field": "name",
           "query": "test test"
        }
    }
}

```

Why? What can I do to fix this?  
Thanks

---

<div class="post-metadata">

**Author:** ![PatrickKik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrickkik/32/619_2.png) [@PatrickKik](https://discuss.elastic.co/u/PatrickKik)\
**Post date:** [August 10, 2015, 5:15am UTC](https://discuss.elastic.co/t/search-query-doesnt-use-custom-analyzer/27075/2 "2015-08-10T05:15:13Z")

</div>

The standard tokenizer will tokenize the input string "test test" to two tokens "test" and "test". Neither of those tokens will be handled by the testsyn filter.  
I think a quick test could be if you use the not\_analyzed tokenizer.

---

<div class="post-metadata">

**Author:** ![Tivak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tivak/32/3610_2.png) [@Tivak](https://discuss.elastic.co/u/Tivak)\
**Post date:** [August 10, 2015, 8:17am UTC](https://discuss.elastic.co/t/search-query-doesnt-use-custom-analyzer/27075/3 "2015-08-10T08:17:08Z")

</div>

I am sorry. query\_string really use custom analyzer, but doesn't apply synonym with 2 words.  
If we add synonym with 1 words, we can see that synonym used.

if we use "match", we see that 2 words synonym works true.  
**But why they don't work with "query\_string"?**

```
POST test/test/_search
{
    "explain": true, 
    "query": {
        "match": {
           "name": "test test"
        }
    }
}

```

> I think a quick test could be if you use the not\_analyzed tokenizer.

What is it "not\_analyzed tokenizer"?

---

<div class="post-metadata">

**Author:** ![PatrickKik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrickkik/32/619_2.png) [@PatrickKik](https://discuss.elastic.co/u/PatrickKik)\
**Post date:** [August 10, 2015, 9:21am UTC](https://discuss.elastic.co/t/search-query-doesnt-use-custom-analyzer/27075/4 "2015-08-10T09:21:07Z")

</div>

> [@Tivak](#):
>
> What is it "not\_analyzed tokenizer"

Didn't know it by heart, had to look it up: I mean the Keyword Tokenizer.

Your answer may be in here: [Multiword Synonyms and Phrase Queries | Elasticsearch: The Definitive Guide [2.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-word-synonyms.html#_synonyms_and_the_query_string_query)

---

<div class="post-metadata">

**Author:** ![Tivak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tivak/32/3610_2.png) [@Tivak](https://discuss.elastic.co/u/Tivak)\
**Post date:** [August 10, 2015, 10:05am UTC](https://discuss.elastic.co/t/search-query-doesnt-use-custom-analyzer/27075/5 "2015-08-10T10:05:18Z")

</div>

> [@PatrickKik](#):
>
> Your answer may be in here: [Multiword Synonyms and Phrase Queries | Elasticsearch: The Definitive Guide [2.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-word-synonyms.html#_synonyms_and_the_query_string_query)

Thanks!!! That explains a lot.  
But how can I use query syntax (OR, AND, NOT etc.) with multi word synonyms?  
Of course, I can split request before sent to ES and use bool query (for example). But I think it is tipical task, and ES can do it 🙂

---

<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 5, 2017, 11:56pm UTC](https://discuss.elastic.co/t/search-query-doesnt-use-custom-analyzer/27075/6 "2017-07-05T23:56:37Z")

</div>


