# Problem in search when using custom analyzer

**URL:** <https://discuss.elastic.co/t/problem-in-search-when-using-custom-analyzer/18406>\
**Category:** Elasticsearch\
**Created:** [July 1, 2014, 4:30am UTC](https://discuss.elastic.co/t/problem-in-search-when-using-custom-analyzer/18406 "2014-07-01T04:30:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robbie](https://avatars.discourse-cdn.com/v4/letter/r/2acd7d/32.png) [@Robbie](https://discuss.elastic.co/u/Robbie)\
**Post date:** [July 1, 2014, 4:30am UTC](https://discuss.elastic.co/t/problem-in-search-when-using-custom-analyzer/18406/1 "2014-07-01T04:30:45Z")

</div>

Hi, I have a use case where I want to search using wild-cards on a custom  
analyzed field. I am currently seeing some discrepancies w.r.t what I  
expect.

Basically, I have string data in a field, such as "Name-55", "Name-56" etc.  
I want to be able to search for "Name-5\*", and get these results.

I have indexed the data into these terms  
"Name", "-", "55"  
"Name", "-", "56"

using a custom pattern analyzer to achieve this. I am using a similar  
custom pattern analyzer for my query string, except that I am swallowing  
any whitespaces, &,? and \*.

"my\_template" : {  
"template" : "_",  
"order": 1,  
"settings" :{  
"analysis": {  
"analyzer": {  
"custom\_index":{  
"type": "pattern",  
"pattern":"([\s]+)|((?\<=\p{L})(?=\P{L})|((?\<=\P{L})(?=\p{L}))|((?\<=\d)(?=\D))|((?\<=\D)(?=\d)))"  
},  
"custom\_search":{  
"type": "pattern",  
"pattern":"([?&_\s]+)|((?\<=\p{L})(?=\P{L})|((?\<=\P{L})(?=\p{L}))|((?\<=\d)(?=\D))|((?\<=\D)(?=\d)))"  
}  
}  
}  
},  
"mappings" : {  
"account" : {  
"properties" : {  
"myfield" : {  
"type" : "string",  
"store" : "yes",  
"index" : "analyzed",  
"index\_analyzer" :"custom\_index",  
"search\_analyzer":"custom\_search"  
}}}}}}

Using this, I see that when I search for "Name-5\*", I do not get any  
results returned.

However, if I search for "Name- 5\*" (Note additional white-space in the  
search string), then I get the results Name-55 and Name-56.

Do you have an understanding of why elasticsearch may be exhibiting this  
behavior? Is there some issue in the way I have setup the patterns in my  
analyzer?

Your help is much appreciated, Thanks!

--  
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/c0a3f237-ea6a-43a7-aefb-c22eb61c75f4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c0a3f237-ea6a-43a7-aefb-c22eb61c75f4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [July 1, 2014, 12:09pm UTC](https://discuss.elastic.co/t/problem-in-search-when-using-custom-analyzer/18406/2 "2014-07-01T12:09:23Z")

</div>

Hello Robbie ,

I feel you are doing it in the wrong direction.

You can use wild card query -

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

But then in the example you have given , this might not work.  
This is because , by default the analyzer in ES will tokenize your Name-55  
into ["Name" , 55]  
Hence it would be a good idea to store the text as it is , and enable a  
normal whitespace tokenizer -

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

After this use the wild card query to search.

Thanks  
Vineeth

On Tue, Jul 1, 2014 at 10:00 AM, Robbie [pherur@ciphercloud.com](mailto:pherur@ciphercloud.com) wrote:

> Hi, I have a use case where I want to search using wild-cards on a  
> custom analyzed field. I am currently seeing some discrepancies w.r.t what  
> I expect.
> 
> Basically, I have string data in a field, such as "Name-55", "Name-56"  
> etc. I want to be able to search for "Name-5\*", and get these results.
> 
> I have indexed the data into these terms  
> "Name", "-", "55"  
> "Name", "-", "56"
> 
> using a custom pattern analyzer to achieve this. I am using a similar  
> custom pattern analyzer for my query string, except that I am swallowing  
> any whitespaces, &,? and \*.
> 
> "my\_template" : {  
> "template" : "_",  
> "order": 1,  
> "settings" :{  
> "analysis": {  
> "analyzer": {  
> "custom\_index":{  
> "type": "pattern",  
> "pattern":"([\s]+)|((?\<=\p{L})(?=\P{L})|((?\<=\P{L})(?=  
> \p{L}))|((?\<=\d)(?=\D))|((?\<=\D)(?=\d)))"  
> },  
> "custom\_search":{  
> "type": "pattern",  
> "pattern":"([?&_\s]+)|((?\<=\p{L})(?=\P{L})|((?\<=\P{L})(?  
> =\p{L}))|((?\<=\d)(?=\D))|((?\<=\D)(?=\d)))"  
> }  
> }  
> }  
> },  
> "mappings" : {  
> "account" : {  
> "properties" : {  
> "myfield" : {  
> "type" : "string",  
> "store" : "yes",  
> "index" : "analyzed",  
> "index\_analyzer" :"custom\_index",  
> "search\_analyzer":"custom\_search"  
> }}}}}}
> 
> Using this, I see that when I search for "Name-5\*", I do not get any  
> results returned.
> 
> However, if I search for "Name- 5\*" (Note additional white-space in the  
> search string), then I get the results Name-55 and Name-56.
> 
> Do you have an understanding of why elasticsearch may be exhibiting this  
> behavior? Is there some issue in the way I have setup the patterns in my  
> analyzer?
> 
> Your help is much appreciated, Thanks!
> 
> --  
> 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/c0a3f237-ea6a-43a7-aefb-c22eb61c75f4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c0a3f237-ea6a-43a7-aefb-c22eb61c75f4%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/c0a3f237-ea6a-43a7-aefb-c22eb61c75f4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c0a3f237-ea6a-43a7-aefb-c22eb61c75f4%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/CAGdPd5%3DRUdG64JQVN-TArHCi%2BdE-p5SEzLjaJKKGN53zhE5pAg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5%3DRUdG64JQVN-TArHCi%2BdE-p5SEzLjaJKKGN53zhE5pAg%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:18am UTC](https://discuss.elastic.co/t/problem-in-search-when-using-custom-analyzer/18406/3 "2017-07-06T01:18:42Z")

</div>


