# How to search with synonym analyzer

**URL:** <https://discuss.elastic.co/t/how-to-search-with-synonym-analyzer/67770>\
**Category:** Elasticsearch\
**Created:** [December 1, 2016, 2:03pm UTC](https://discuss.elastic.co/t/how-to-search-with-synonym-analyzer/67770 "2016-12-01T14:03:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)\
**Post date:** [December 1, 2016, 2:03pm UTC](https://discuss.elastic.co/t/how-to-search-with-synonym-analyzer/67770/1 "2016-12-01T14:03:54Z")

</div>

Here are my index setting and mapping

M using the synonym analyzer over the fields and in search i want to search in all the fields of an index.

analysis": {  
"filter": {  
"synonym": {  
"type": "synonym",  
"synonyms\_path": "D:\MyElasticSearch\elasticsearch-1.5.2\config\synonyms.txt",  
"ignore\_case": "true"  
}  
},  
"analyzer": {  
"synonym": {  
"filter": [  
"synonym"  
],  
"tokenizer": "whitespace"  
}  
}  
}  
Here is the mapping

"BrandDesc": {  
"type": "string",  
"index": "not\_analyzed",  
"analyzer": "synonym",  
"fields": {  
"raw": {  
"type": "string",  
"analyzer": "synonym"  
}  
}  
},  
when i search with the query with normal query string it's giving me count say 1200

GET newpcdb\_anlyz/\_search  
{  
"query": {  
"query\_string": {  
"query": "engine"  
}  
}  
}  
But same when I query with analyzer synonyms its giving me less count,(it should give more than 1200 as it will include engine synonyms also in search)

GET newpcdb\_anlyz/\_search  
{  
"query": {  
"query\_string": {  
"query": "engine",  
"analyzer": "synonym"  
}  
}  
}  
M I missing something

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [December 1, 2016, 2:25pm UTC](https://discuss.elastic.co/t/how-to-search-with-synonym-analyzer/67770/2 "2016-12-01T14:25:02Z")

</div>

Search matching occurs when the tokens in your search match those in your index.  
The tool for debugging how a query is (or isn't) matching is the explain API [1].  
It should show you the tokens your query is executing at a low level.  
If some of the tokens are unexpected you can use the analyze API [2] to debug what tokens your query and your document produce.

[1] [https://www.elastic.co/guide/en/elasticsearch/reference/5.0/search-explain.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/search-explain.html)  
[2] [https://www.elastic.co/guide/en/elasticsearch/reference/5.0/\_testing\_analyzers.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/_testing_analyzers.html)

---

<div class="post-metadata">

**Author:** ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)\
**Post date:** [December 1, 2016, 2:34pm UTC](https://discuss.elastic.co/t/how-to-search-with-synonym-analyzer/67770/3 "2016-12-01T14:34:08Z")

</div>

Thanks Mark for your remark's,I will chek with the above API & will get back ,if I have any queries.

---

<div class="post-metadata">

**Author:** ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)\
**Post date:** [December 1, 2016, 3:23pm UTC](https://discuss.elastic.co/t/how-to-search-with-synonym-analyzer/67770/4 "2016-12-01T15:23:08Z")

</div>

Hi Mark

I have debugged the query and found that

GET /newpcdb\_prasad/newpcdb\_prasad\_type/180080/\_explain

{  
"query" : {  
"query\_string": {  
"query": "machine"  
}  
}  
}

If I use this query m getting matched as true but when I search with analyzer m getting the match as false.

GET /newpcdb\_prasad/newpcdb\_prasad\_type/180080/\_explain

{  
"query" : {  
"query\_string": {  
"query": "machine",  
"analyzer": "synonym"  
}  
}  
}

getting the response as match false.

However, when I check what kind of tokens have been generated by analyzing test I do found machine in document 180080

GET newpcdb\_prasad/\_analyze?text=Forney .......some text....&analyzer=synonym&tokenizer=whitespace

m getting a token of a machine

```
{
  "token": "machine",
  "start_offset": 254,
  "end_offset": 261,
  "type": "SYNONYM",
  "position": 43
},

```

Could you please help me out , ....as its is priority issue to me

---

<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:** [December 29, 2016, 3:23pm UTC](https://discuss.elastic.co/t/how-to-search-with-synonym-analyzer/67770/5 "2016-12-29T15:23:07Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
