# Elasticsearch query issue with reserved characters

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-issue-with-reserved-characters/149235>\
**Category:** Elasticsearch\
**Created:** [September 20, 2018, 6:37am UTC](https://discuss.elastic.co/t/elasticsearch-query-issue-with-reserved-characters/149235 "2018-09-20T06:37:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikesh/32/86579_2.png) [@Nikesh](https://discuss.elastic.co/u/Nikesh)\
**Post date:** [September 20, 2018, 6:37am UTC](https://discuss.elastic.co/t/elasticsearch-query-issue-with-reserved-characters/149235/1 "2018-09-20T06:37:30Z")

</div>

Hi all,  
I have indexed two documents

1. {"title": "+" }
2. {"title": "a + b" }  
By using query string query , I have search queries for the above two documents in different manner.  
Also, I have not changed any analyzers. Default analyzer has been used.

1. {  
"query": {  
"query\_string" : {  
"default\_field" : "title",  
"query" : "+"  
}  
}  
}  
the above query gives a parsing exception which is legit.

2.{  
"query": {  
"query\_string" : {  
"default\_field" : "title",  
"query" : "\+"  
}  
}  
}  
this query outputs:

"hits": [  
{  
"\_index": "my\_index1",  
"\_type": "my\_item",  
"\_id": "005",  
"\_score": 0.9808292,  
"\_source": {  
"title": "+"  
}  
}  
]  
the above output also seems legit.

1. {  
"query": {  
"query\_string" : {  
"default\_field" : "title",  
"query" : " + "  
}  
}  
}  
in the above query space exists before and after "+" character , this outputs:  
"hits": [  
{  
"\_index": "my\_index1",  
"\_type": "my\_item",  
"\_id": "005",  
"\_score": 1.2039728,  
"\_source": {  
"title": "+"  
}  
}  
]  
My issue is why parsing exception is not thrown here and why escaping "+" is not necessary here"? If Elasticsearch is finding a way to parse "+"in some manner, why is "a + b" not in the hits?

4.{  
"query": {  
"query\_string" : {  
"default\_field" : "title",  
"query" : "a + b"  
}  
}  
}  
this query outputs:  
"hits": [  
{  
"\_index": "my\_index1",  
"\_type": "my\_item",  
"\_id": "005",  
"\_score": 0.9808292,  
"\_source": {  
"title": "+"  
}  
}  
]  
I don't understand how my query is parsing "+" and not throwing an exception. If Elasticsearch is finding a way to parse "+"in some manner, why is "a + b" not in the hits?

1. {  
"query": {  
"query\_string" : {  
"default\_field" : "title",  
"query" : "a \+ b"  
}  
}  
}  
output to this query :  
"max\_score": 0.6931472,  
"hits": [  
{  
"\_index": "my\_index1",  
"\_type": "my\_item",  
"\_id": "007",  
"\_score": 0.6931472,  
"\_source": {  
"title": "a + b"  
}  
}  
]

if the query is using default analyzers (since I have not used any analyzers) how is "+" not in the hits here?

---

<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:** [October 18, 2018, 6:37am UTC](https://discuss.elastic.co/t/elasticsearch-query-issue-with-reserved-characters/149235/2 "2018-10-18T06:37:38Z")

</div>

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