# Searching Special Charactes like &%\*@()!{} etc in 0.13

**URL:** <https://discuss.elastic.co/t/searching-special-charactes-like-etc-in-0-13/3596>\
**Category:** Elasticsearch\
**Created:** [November 24, 2010, 7:22am UTC](https://discuss.elastic.co/t/searching-special-charactes-like-etc-in-0-13/3596 "2010-11-24T07:22:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![B\_Rajan](https://avatars.discourse-cdn.com/v4/letter/b/76d3ee/32.png) [@B\_Rajan](https://discuss.elastic.co/u/B_Rajan)\
**Post date:** [November 24, 2010, 7:22am UTC](https://discuss.elastic.co/t/searching-special-charactes-like-etc-in-0-13/3596/1 "2010-11-24T07:22:34Z")

</div>

Hi,

How can we searh the special characters &%\*@()!{} in Elastic Search  
0.13.

For example:

{ "query" : { "query\_string" : { "default\_field" : "", "query" :  
"elastic(","default\_operator" : "OR","analyzer" :  
"Standard","allow\_leading\_wildcard" :  
true,"lowercase\_expanded\_terms" : true,"enable\_position\_increments" :  
true,"fuzzy\_prefix\_length" : 0,"fuzzy\_min\_sim" : 0.5,"phrase\_slop" :  
0,"boost" : 1.0 } }, "from" : 0, "size" : 0, "explain" : false }

Here I am trying to search for a word "elastic(" with a open  
paranthesis at the end. I used the escape character \ but still not  
working.

Please help.

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [November 24, 2010, 10:09am UTC](https://discuss.elastic.co/t/searching-special-charactes-like-etc-in-0-13/3596/2 "2010-11-24T10:09:45Z")

</div>

Hi,

It is important how you analyze text during indexing (and query time as  
well). You can check with a new Analyzer API how your terms are handled with  
your analyzers. The mentioned feature is in master, see  
[Analyze API: An API to analyzer custom text based on an optional analyzer · Issue #529 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/issue/529) for more  
details.

Providing the "&%_@()!{}" is URL encoded to "%26%25_%40()!%7b%7d".

Using default analyzer (standard)

curl -XGET '[http://localhost:9200/myindex/\_analyze?text=%26%25\*%40()!{}](http://localhost:9200/myindex/_analyze?text=%26%25*%40()!%7b%7d)'  
{"tokens":}

Using keyword analyzer:

curl -XGET '  
[http://localhost:9200/myindex/\_analyze?analyzer=keyword&text=%26%25\*%40()!{}](http://localhost:9200/myindex/_analyze?analyzer=keyword&text=%26%25*%40()!%7b%7d)  
'  
{"tokens":[{"token":"&%\*@()!{}","start\_offset":0,"end\_offset":9,"type":"word","position":1}]}

Typically you want to use the same analysis process for both indexing and  
query time.

So imagine the following:

start ES with defaults

curl -XDELETE [http://localhost:9200/myindex](http://localhost:9200/myindex)  
curl -XPUT [http://localhost:9200/myindex/](http://localhost:9200/myindex/) -d  
'{"index":{"number\_of\_shards":1,"number\_of\_replicas":0}}'  
curl -XPUT '[http://localhost:9200/myindex/mytype/1?refresh=true](http://localhost:9200/myindex/mytype/1?refresh=true)' -d  
'{"field1":"text("}'  
curl -XGET [http://localhost:9200/\_search?refresh=true](http://localhost:9200/_search?refresh=true) -d '{  
"query":{"term":{"field1":"text("}}}'  
curl -XGET [http://localhost:9200/\_search](http://localhost:9200/_search) -d  
'{"query":{"query\_string":{"query":""text(""}}}'

The above sequence of calls to REST API do the following:

1. delete the index
2. create the index
3. index one document (and refresh so that we can immediately search for it)
4. use term API[http://localhost:4000/docs/elasticsearch/rest\_api/query\_dsl/term\_query/](http://localhost:4000/docs/elasticsearch/rest_api/query_dsl/term_query/)to  
search for the exact match on "text("
5. use query\_string API to search on "text(" (note using phrase query syntax  
otherwise you get Lucene query parser exception)

Interestingly 4) does not find anything and 5) does find the document. Why?  
Because "text(" is by default tokenized to "text".

curl -XGET '[http://localhost:9200/myindex/\_analyze?text=text](http://localhost:9200/myindex/_analyze?text=text)('  
{"tokens":[{"token":"text","start\_offset":0,"end\_offset":4,"type":"","position":1}]}

So you have to set appropriate analyzers to be able to search on specific  
characters. May be you want to use standard analyzer on your text and put  
specific terms into a new filed which is not analyzed during indexing.

Also note that there are some issues in your query:

1. default\_field - why do you set it to empty string?
2. Query DSL is case sensitive so note you used "Standard" analyzer instead  
of "standard"

Regards,  
Lukas

On Wed, Nov 24, 2010 at 8:22 AM, B Rajan [boopsraj@gmail.com](mailto:boopsraj@gmail.com) wrote:

> Hi,
> 
> How can we searh the special characters &%\*@()!{} in Elastic Search  
> 0.13.
> 
> For example:
> 
> { "query" : { "query\_string" : { "default\_field" : "", "query" :  
> "elastic(","default\_operator" : "OR","analyzer" :  
> "Standard","allow\_leading\_wildcard" :  
> true,"lowercase\_expanded\_terms" : true,"enable\_position\_increments" :  
> true,"fuzzy\_prefix\_length" : 0,"fuzzy\_min\_sim" : 0.5,"phrase\_slop" :  
> 0,"boost" : 1.0 } }, "from" : 0, "size" : 0, "explain" : false }
> 
> Here I am trying to search for a word "elastic(" with a open  
> paranthesis at the end. I used the escape character \ but still not  
> working.
> 
> Please help.

---

<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, 4:16am UTC](https://discuss.elastic.co/t/searching-special-charactes-like-etc-in-0-13/3596/3 "2017-07-06T04:16:08Z")

</div>


