# Characters that cause query to Fail

**URL:** <https://discuss.elastic.co/t/characters-that-cause-query-to-fail/8531>\
**Category:** Elasticsearch\
**Created:** [July 26, 2012, 7:43pm UTC](https://discuss.elastic.co/t/characters-that-cause-query-to-fail/8531 "2012-07-26T19:43:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Hilkert](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_hilkert/32/2182_2.png) [@Brandon\_Hilkert](https://discuss.elastic.co/u/Brandon_Hilkert)\
**Post date:** [July 26, 2012, 7:43pm UTC](https://discuss.elastic.co/t/characters-that-cause-query-to-fail/8531/1 "2012-07-26T19:43:10Z")

</div>

We're doing some sample queries and found that a query with "!" causes the  
search to fail.

A couple questions:

- Is this expected?
- If so, are there other characters we should remove before querying?

---

<div class="post-metadata">

**Author:** ![Praveen\_Kariyanahall](https://avatars.discourse-cdn.com/v4/letter/p/4491bb/32.png) [@Praveen\_Kariyanahall](https://discuss.elastic.co/u/Praveen_Kariyanahall)\
**Post date:** [July 26, 2012, 7:50pm UTC](https://discuss.elastic.co/t/characters-that-cause-query-to-fail/8531/2 "2012-07-26T19:50:59Z")

</div>

> Did you try escaping it ? I also have the same issue with ":" and "/". But  
> I am not sure the issue is with indexing or searching ?

Try escaping the character and run the query("!"), see if that helps.

-pk

---

<div class="post-metadata">

**Author:** ![Brandon\_Hilkert](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_hilkert/32/2182_2.png) [@Brandon\_Hilkert](https://discuss.elastic.co/u/Brandon_Hilkert)\
**Post date:** [July 26, 2012, 7:57pm UTC](https://discuss.elastic.co/t/characters-that-cause-query-to-fail/8531/3 "2012-07-26T19:57:19Z")

</div>

Ah....gotcha. Cool. That fixed it!

On Thursday, July 26, 2012 3:50:59 PM UTC-4, Praveen Kariyanahalli wrote:

> Did you try escaping it ? I also have the same issue with ":" and "/". But
> 
> > I am not sure the issue is with indexing or searching ?
> 
> Try escaping the character and run the query("!"), see if that helps.
> 
> -pk

---

<div class="post-metadata">

**Author:** ![Chris\_Male](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_male/32/2607_2.png) [@Chris\_Male](https://discuss.elastic.co/u/Chris_Male)\
**Post date:** [July 27, 2012, 7:11am UTC](https://discuss.elastic.co/t/characters-that-cause-query-to-fail/8531/4 "2012-07-27T07:11:10Z")

</div>

Hi Brandon,

> - If so, are there other characters we should remove before querying?

There are a number of special characters to watch out for. See the list at  
the bottom of [Apache Lucene - Query Parser Syntax](http://lucene.apache.org/core/3_6_0/queryparsersyntax.html)

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [July 28, 2012, 9:28am UTC](https://discuss.elastic.co/t/characters-that-cause-query-to-fail/8531/5 "2012-07-28T09:28:48Z")

</div>

Brandon,

if you don't need query parser support ie. you don't expose operators like  
AND, OR, NOT or phrases "foo bar" you can simply use a text query which  
only goes through and analyzer without going through a QueryParser so you  
don't need to worry about characters and escaping. this has also benefits  
in security since nobody can issue very slow searches like fuzzy query like  
foo~2 or wildcards like a\*

here is a  
link: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html)

simon

On Friday, July 27, 2012 9:11:10 AM UTC+2, Chris Male wrote:

> Hi Brandon,
> 
> > - If so, are there other characters we should remove before querying?
> 
> There are a number of special characters to watch out for. See the list  
> at the bottom of  
> [Apache Lucene - Query Parser Syntax](http://lucene.apache.org/core/3_6_0/queryparsersyntax.html)

---

<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/characters-that-cause-query-to-fail/8531/6 "2017-07-06T03:18:40Z")

</div>


