# Escapting special character during search is not working for not\_analyzed field

**URL:** <https://discuss.elastic.co/t/escapting-special-character-during-search-is-not-working-for-not-analyzed-field/8538>\
**Category:** Elasticsearch\
**Created:** [July 27, 2012, 1:17pm UTC](https://discuss.elastic.co/t/escapting-special-character-during-search-is-not-working-for-not-analyzed-field/8538 "2012-07-27T13:17:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![manoj\_2](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@manoj\_2](https://discuss.elastic.co/u/manoj_2)\
**Post date:** [July 27, 2012, 1:17pm UTC](https://discuss.elastic.co/t/escapting-special-character-during-search-is-not-working-for-not-analyzed-field/8538/1 "2012-07-27T13:17:50Z")

</div>

Hi All,

Please excuse if it is already asked.

I am facing a weird situation of search not returning any hits, even on  
escaping the special characters during search. The search field is  
not\_analyzed.

This is how data is indexed in the cluster.

{  
"took":516,  
"timed\_out":false,  
"\_shards":{  
"total":1,  
"successful":1,  
"failed":0  
},  
"hits":{  
"total":2,  
"max\_score":1.0,  
"hits":[  
{  
"\_index":"moreovercontact",  
"\_type":"moreovercontact",  
"\_id":"1322",  
"\_score":1.0,  
"\_source":{  
"contactid":"1322",  
"contactname":"Wanda "Blueberry Freak" C.",  
"email":"",  
"sourceid":"4715"  
}  
}  
]  
}  
}

The search request builder I used to pick data from the index is:

{  
"from":0,  
"size":10,  
"query":{  
"bool":{  
"should":{  
"bool":{  
"must":[  
{  
"query\_string":{  
"query":"Wanda "Blueberry Freak" C.",  
"fields":[  
"contactname.sort"  
],  
"use\_dis\_max":true  
}  
},  
{  
"query\_string":{  
"query":"4715",  
"fields":[  
"sourceid"  
],  
"use\_dis\_max":true  
}  
}  
]  
}  
}  
}  
},  
"explain":true,  
"fields":[  
"contactid",  
"contactname"  
]  
}

Hope I have escaped the special character in the query string in right  
way. Let me know if I need to provide any more information regarding this

Could anybody help me on this problem?

Thank You!  
Manoj

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [July 27, 2012, 4:28pm UTC](https://discuss.elastic.co/t/escapting-special-character-during-search-is-not-working-for-not-analyzed-field/8538/2 "2012-07-27T16:28:14Z")

</div>

The query\_string query is parsing the query string. It uses spaces to split  
the query string into clauses and as a result your query is getting  
translated into something like:

```
contactname.sort:Wanda OR contactname.sort:"Blueberry Freak" 

```

OR contactname.sort:C.

To force query\_string to treat your query as a single term, you need  
another pair of quotes:

```
"query":"\"Wanda \\\"Blueberry Freak\\\" C.\"",

```

However, considering that your field is not analyzed, it would be more  
efficient to simply use "term" query instead of query\_string.

On Friday, July 27, 2012 9:17:50 AM UTC-4, Manoj wrote:

> Hi All,
> 
> Please excuse if it is already asked.
> 
> I am facing a weird situation of search not returning any hits, even on  
> escaping the special characters during search. The search field is  
> not\_analyzed.
> 
> This is how data is indexed in the cluster.
> 
> {  
> "took":516,  
> "timed\_out":false,  
> "\_shards":{  
> "total":1,  
> "successful":1,  
> "failed":0  
> },  
> "hits":{  
> "total":2,  
> "max\_score":1.0,  
> "hits":[  
> {  
> "\_index":"moreovercontact",  
> "\_type":"moreovercontact",  
> "\_id":"1322",  
> "\_score":1.0,  
> "\_source":{  
> "contactid":"1322",  
> "contactname":"Wanda "Blueberry Freak" C.",  
> "email":"",  
> "sourceid":"4715"  
> }  
> }  
> ]  
> }  
> }
> 
> The search request builder I used to pick data from the index is:
> 
> {  
> "from":0,  
> "size":10,  
> "query":{  
> "bool":{  
> "should":{  
> "bool":{  
> "must":[  
> {  
> "query\_string":{  
> "query":"Wanda "Blueberry Freak" C.",  
> "fields":[  
> "contactname.sort"  
> ],  
> "use\_dis\_max":true  
> }  
> },  
> {  
> "query\_string":{  
> "query":"4715",  
> "fields":[  
> "sourceid"  
> ],  
> "use\_dis\_max":true  
> }  
> }  
> ]  
> }  
> }  
> }  
> },  
> "explain":true,  
> "fields":[  
> "contactid",  
> "contactname"  
> ]  
> }
> 
> Hope I have escaped the special character in the query string in right  
> way. Let me know if I need to provide any more information regarding this
> 
> Could anybody help me on this problem?
> 
> Thank You!  
> Manoj

---

<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:18am UTC](https://discuss.elastic.co/t/escapting-special-character-during-search-is-not-working-for-not-analyzed-field/8538/3 "2017-07-06T03:18:46Z")

</div>


