# Search with special caracters

**URL:** <https://discuss.elastic.co/t/search-with-special-caracters/8181>\
**Category:** Elasticsearch\
**Created:** [June 21, 2012, 2:12pm UTC](https://discuss.elastic.co/t/search-with-special-caracters/8181 "2012-06-21T14:12:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Taieb](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@Taieb](https://discuss.elastic.co/u/Taieb)\
**Post date:** [June 21, 2012, 2:12pm UTC](https://discuss.elastic.co/t/search-with-special-caracters/8181/1 "2012-06-21T14:12:47Z")

</div>

Hi,

how can i search for fields that contain special caracters like : @ , | - \_  
? \* ...  
I try query\_string, wildcard but it doesn't work !

Thanks

---

<div class="post-metadata">

**Author:** ![AEvar\_Arnfjord\_Bjarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aevar_arnfjord_bjarm/32/2746_2.png) [@AEvar\_Arnfjord\_Bjarm](https://discuss.elastic.co/u/AEvar_Arnfjord_Bjarm)\
**Post date:** [June 22, 2012, 11:33am UTC](https://discuss.elastic.co/t/search-with-special-caracters/8181/2 "2012-06-22T11:33:17Z")

</div>

This comes down to what analyzer you use:

$ searchanalyze -t '@ , | - \_ ? \*'  
We analyzed \<@ , | - \_ ? \*\> with as \<{  
'tokens' =\>   
}

> 

$ searchanalyze -a keyword -t '@ , | - \_ ? \*'  
We analyzed \<@ , | - \_ ? \*\> with as \<{  
'tokens' =\> [  
{  
'end\_offset' =\> 13,  
'position' =\> 1,  
'start\_offset' =\> 0,  
'token' =\> '@ , | - \_ ? \*',  
'type' =\> 'word'  
}  
]  
}

> 

As you can see the standard analyzer completely ignores all those  
special characters. You could use the whitespace analyzer:

$ searchanalyze -a whitespace -t '@ , | - \_ ? _'|grep token  
'tokens' =\> [  
'token' =\> '@',  
'token' =\> ',',  
'token' =\> '|',  
'token' =\> '-',  
'token' =\> '\_',  
'token' =\> '?',  
'token' =\> '_',

But you should think carefully about what characters you want to make  
searchable, some of them, all of them, in what context etc.

---

<div class="post-metadata">

**Author:** ![Taieb](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@Taieb](https://discuss.elastic.co/u/Taieb)\
**Post date:** [June 22, 2012, 2:24pm UTC](https://discuss.elastic.co/t/search-with-special-caracters/8181/3 "2012-06-22T14:24:37Z")

</div>

Thank you AEvar,

$ searchanalyze -a whitespace -t '@ , | - \_ ? _'|grep token  
'tokens' =\> [  
'token' =\> '@',  
'token' =\> ',',  
'token' =\> '|',  
'token' =\> '-',  
'token' =\> '\_',  
'token' =\> '?',  
'token' =\> '_',

but how can I use searchanalyze !(currently I use elasticsearch.yml to  
change the analyzer)

On Fri, Jun 22, 2012 at 1:33 PM, Ævar Arnfjörð Bjarmason  
[avarab@gmail.com](mailto:avarab@gmail.com)wrote:

> This comes down to what analyzer you use:
> 
> $ searchanalyze -t '@ , | - \_ ? \*'  
> We analyzed \<@ , | - \_ ? \*\> with as \<{  
> 'tokens' =\>   
> }
> 
> > 
> 
> $ searchanalyze -a keyword -t '@ , | - \_ ? \*'  
> We analyzed \<@ , | - \_ ? \*\> with as \<{  
> 'tokens' =\> [  
> {  
> 'end\_offset' =\> 13,  
> 'position' =\> 1,  
> 'start\_offset' =\> 0,  
> 'token' =\> '@ , | - \_ ? \*',  
> 'type' =\> 'word'  
> }  
> ]  
> }
> 
> > 
> 
> As you can see the standard analyzer completely ignores all those  
> special characters. You could use the whitespace analyzer:
> 
> $ searchanalyze -a whitespace -t '@ , | - \_ ? _'|grep token  
> 'tokens' =\> [  
> 'token' =\> '@',  
> 'token' =\> ',',  
> 'token' =\> '|',  
> 'token' =\> '-',  
> 'token' =\> '\_',  
> 'token' =\> '?',  
> 'token' =\> '_',
> 
> But you should think carefully about what characters you want to make  
> searchable, some of them, all of them, in what context etc.

--  
Taieb Charrada  
élève ingénieur en 3ème année Informatique à l'ENIT  
Tel : 06 52 37 18 39  
E-mail : _[taieb.charrada@gmail.com](mailto:taieb.charrada@gmail.com)_

---

<div class="post-metadata">

**Author:** ![AEvar\_Arnfjord\_Bjarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aevar_arnfjord_bjarm/32/2746_2.png) [@AEvar\_Arnfjord\_Bjarm](https://discuss.elastic.co/u/AEvar_Arnfjord_Bjarm)\
**Post date:** [June 22, 2012, 3:07pm UTC](https://discuss.elastic.co/t/search-with-special-caracters/8181/4 "2012-06-22T15:07:11Z")

</div>

On Fri, Jun 22, 2012 at 4:24 PM, Taieb CHARRADA  
[taieb.charrada@gmail.com](mailto:taieb.charrada@gmail.com) wrote:

> but how can I use searchanalyze !(currently I use elasticsearch.yml to  
> change the analyzer)

It's a small wrapper I wrote that I haven't gotten around to open sourcing.

---

<div class="post-metadata">

**Author:** ![Taieb](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@Taieb](https://discuss.elastic.co/u/Taieb)\
**Post date:** [June 22, 2012, 3:26pm UTC](https://discuss.elastic.co/t/search-with-special-caracters/8181/5 "2012-06-22T15:26:29Z")

</div>

So could you explain to me how can I create a custom whitespace tokenizer?  
cause at least I create a keyword tokenizer in my yml file and for some  
caracters like "@" "," "-" it works but for others like "(" ")" "!" it must  
write query = _""text)""_ to find \*text) _and in this case I can't search  
it with only a keyword like text)_

On Fri, Jun 22, 2012 at 5:07 PM, Ævar Arnfjörð Bjarmason  
[avarab@gmail.com](mailto:avarab@gmail.com)wrote:

> On Fri, Jun 22, 2012 at 4:24 PM, Taieb CHARRADA  
> [taieb.charrada@gmail.com](mailto:taieb.charrada@gmail.com) wrote:
> 
> > but how can I use searchanalyze !(currently I use elasticsearch.yml to  
> > change the analyzer)
> 
> It's a small wrapper I wrote that I haven't gotten around to open sourcing.

--  
Taieb Charrada  
élève ingénieur en 3ème année Informatique à l'ENIT  
Tel : 06 52 37 18 39  
E-mail : _[taieb.charrada@gmail.com](mailto:taieb.charrada@gmail.com)_

---

<div class="post-metadata">

**Author:** ![AEvar\_Arnfjord\_Bjarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aevar_arnfjord_bjarm/32/2746_2.png) [@AEvar\_Arnfjord\_Bjarm](https://discuss.elastic.co/u/AEvar_Arnfjord_Bjarm)\
**Post date:** [June 22, 2012, 3:43pm UTC](https://discuss.elastic.co/t/search-with-special-caracters/8181/6 "2012-06-22T15:43:18Z")

</div>

On Fri, Jun 22, 2012 at 5:26 PM, Taieb CHARRADA  
[taieb.charrada@gmail.com](mailto:taieb.charrada@gmail.com) wrote:

> So could you explain to me how can I create a custom whitespace tokenizer?  
> cause at least I create a keyword tokenizer in my yml file and for some  
> caracters like "@" "," "-" it works but for others like "(" ")" "!" it must  
> write query = ""text)"" to find text) and in this case I can't search it  
> with only a keyword like text)\*

Read up on mappings and analyzers in the ES manual. Basically ES takes  
the text you feed it and analyzes it (tokenizes it) before adding it  
to the index.

If you want to search for something it needs to be in the index, with  
the standard tokenizer the punctuation you want to search for will be  
filtered out.

---

<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, 3:22am UTC](https://discuss.elastic.co/t/search-with-special-caracters/8181/7 "2017-07-06T03:22:55Z")

</div>


