# Custom Search analyzer

**URL:** <https://discuss.elastic.co/t/custom-search-analyzer/69033>\
**Category:** Elasticsearch\
**Created:** [December 14, 2016, 3:09pm UTC](https://discuss.elastic.co/t/custom-search-analyzer/69033 "2016-12-14T15:09:39Z")\
**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 14, 2016, 3:09pm UTC](https://discuss.elastic.co/t/custom-search-analyzer/69033/1 "2016-12-14T15:09:39Z")

</div>

Hi Team,

I got stuck in very interesting issue.

I have implemented synonyms feature in my index, its working fine.

in my synonyms file, i have oil, lube,lubricate.

when I search with oil, Es is automatically searching for lube & lubricate,it's working as expected.

But the problem is when I search with **oil filter** term its hitting the document which contains **lube filter** as well I don't want this to happen is there any filter/analyzer which will search with the given words excluding its synonyms.

Here is the setting and mapping

"filter": {  
"synonym": {  
"type": "synonym",  
"synonyms\_path": "D:\MyElasticSearch\elasticsearch-1.5.2\config\synonymsnew.txt",  
"ignore\_case": "true"  
},

"analyzer": {  
"synonym": {  
"filter": [  
"synonym"  
],  
"tokenizer": "whitespace"

Here is my mapping

"BrandName": {  
"type": "string",  
"index\_analyzer": "synonym",  
"search\_analyzer": "standard",  
"fields": {  
"raw": {  
"type": "string"  
}  
},

And My search query is this

GET /\_search  
{  
"query": {  
"bool": {  
"must": [  
{  
"query\_string": {  
"query": "oil filter",  
"default\_operator": "AND"  
}  
}  
]  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [December 14, 2016, 4:04pm UTC](https://discuss.elastic.co/t/custom-search-analyzer/69033/2 "2016-12-14T16:04:04Z")

</div>

Hi,

afaik, when you use a synonyms analyzer at index time, it "replace" in the analyzed field terms, so in the destination field when you index "oil", it puts "oil, lube,lubricate". So it's normal that you find the document when searching "lube".

Xavier

---

<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 15, 2016, 7:14am UTC](https://discuss.elastic.co/t/custom-search-analyzer/69033/3 "2016-12-15T07:14:47Z")

</div>

yes exactly Xavier but when I search with **oil filter** it should search exactly oil filter not **lube filter** ,

is there any way to sort this out.

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [December 15, 2016, 10:03am UTC](https://discuss.elastic.co/t/custom-search-analyzer/69033/4 "2016-12-15T10:03:24Z")

</div>

According to your synonyms when you index "oil filter" or "lube filter", Elasticsearch stores "oil lube lubricate filter", so that's normal that when you search "oil filter" it match "lube filter"...

---

<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:** [January 12, 2017, 10:03am UTC](https://discuss.elastic.co/t/custom-search-analyzer/69033/5 "2017-01-12T10:03:27Z")

</div>

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