# Escaping Special Characters in Wildcard Query

**URL:** <https://discuss.elastic.co/t/escaping-special-characters-in-wildcard-query/5819>\
**Category:** Elasticsearch\
**Created:** [November 8, 2011, 8:53pm UTC](https://discuss.elastic.co/t/escaping-special-characters-in-wildcard-query/5819 "2011-11-08T20:53:48Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [November 9, 2011, 8:39am UTC](https://discuss.elastic.co/t/escaping-special-characters-in-wildcard-query/5819/2 "2011-11-09T08:39:11Z")

</div>

Hi Dawi

> The elasticsearch documentation says that "The wildcard query maps to  
> lucene WildcardQuery".  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/wildcard-query.html)

> The Lucene documentation says that there is the following list of  
> special characters:
> 
> - 
> - && || ! ( ) { } ^ " ~ \* ? :   
> and that they can be escaped using the \ before the character.  
> [Apache Lucene - Query Parser Syntax](http://lucene.apache.org/java/3_4_0/queryparsersyntax.html#Escaping%25)  
> 20Special%20Characters

These special characters apply to the query\_string/field query, not to  
the wildcard query. The only special characters in the wildcard query  
are \* and ?

> I have tried every form of escaping I can imagine but I was not able  
> to search for \* and ? using a wildcard query.

I'm guessing that the field that you are trying to search against is  
analyzed with the standard analyzer? In which case, most punctuation is  
removed, so characters like \* will not exist in your terms, and thus  
won't be searchable

Depending on what your data is, it make make sense to set your field to  
{ index: not\_analyzed}

clint

---

_[View the full topic](https://discuss.elastic.co/t/escaping-special-characters-in-wildcard-query/5819)._
