# Exclamation point breaks field queries

**URL:** <https://discuss.elastic.co/t/exclamation-point-breaks-field-queries/6460>\
**Category:** Elasticsearch\
**Created:** [January 21, 2012, 10:18pm UTC](https://discuss.elastic.co/t/exclamation-point-breaks-field-queries/6460 "2012-01-21T22:18:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Hoffman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_hoffman/32/1872_2.png) [@Nick\_Hoffman](https://discuss.elastic.co/u/Nick_Hoffman)\
**Post date:** [January 21, 2012, 10:18pm UTC](https://discuss.elastic.co/t/exclamation-point-breaks-field-queries/6460/1 "2012-01-21T22:18:00Z")

</div>

Hey guys. I just noticed that a field query that includes an exclamation  
point ("!") results in a failed query. Eg:

curl 'localhost:9200/development\_products/product/\_search?pretty=true' -d '  
{  
"query" : {  
"dis\_max" : {  
"queries" : [  
{ "field" : {"name" : "Arise!"}},  
{ "field" : {"catalog.name" : "Arise!"}}  
]  
}  
}  
}'

Here's a gist with more details:

> <https://gist.github.com/nickhoffman/1654247>

Is this supposed to happen?

Thanks,  
Nick

---

<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:** [January 22, 2012, 10:58am UTC](https://discuss.elastic.co/t/exclamation-point-breaks-field-queries/6460/2 "2012-01-22T10:58:45Z")

</div>

On Sat, 2012-01-21 at 14:18 -0800, Nick Hoffman wrote:

> Hey guys. I just noticed that a field query that includes an  
> exclamation point ("!") results in a failed query. Eg:

Yes - the query parameter should be in the Lucene query parser syntax:  
[http://lucene.apache.org/java/3\_5\_0/queryparsersyntax.html](http://lucene.apache.org/java/3_5_0/queryparsersyntax.html)

> 

If you don't want to use the lucene query parser syntax features  
ie: field: + - AND OR NOT ~ ^ ()  
then rather use a 'text' query. If you DO want to use these features,  
then you need to preparse your query string to remove or escape any  
illegal characters.

In the Perl API, I provide a module to do just that:  
[https://metacpan.org/module/ElasticSearch::QueryParser](https://metacpan.org/module/ElasticSearch::QueryParser)

clint

> curl 'localhost:9200/development\_products/product/\_search?pretty=true'  
> -d '  
> {  
> "query" : {  
> "dis\_max" : {  
> "queries" : [  
> { "field" : {"name" : "Arise!"}},  
> { "field" : {"catalog.name" : "Arise!"}}  
> ]  
> }  
> }  
> }'
> 
> Here's a gist with more details:  
> [query\_with\_exclamation.sh · GitHub](https://gist.github.com/1654247)
> 
> Is this supposed to happen?
> 
> Thanks,  
> Nick

---

<div class="post-metadata">

**Author:** ![Nick\_Hoffman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_hoffman/32/1872_2.png) [@Nick\_Hoffman](https://discuss.elastic.co/u/Nick_Hoffman)\
**Post date:** [January 22, 2012, 9:33pm UTC](https://discuss.elastic.co/t/exclamation-point-breaks-field-queries/6460/3 "2012-01-22T21:33:02Z")

</div>

Awesome. Thanks for the explanation and links, Clint! Those're very helpful.

---

<div class="post-metadata">

**Author:** ![vallabh\_2](https://avatars.discourse-cdn.com/v4/letter/v/7ab992/32.png) [@vallabh\_2](https://discuss.elastic.co/u/vallabh_2)\
**Post date:** [November 1, 2013, 11:58am UTC](https://discuss.elastic.co/t/exclamation-point-breaks-field-queries/6460/4 "2013-11-01T11:58:02Z")

</div>

Hi Clint,

Exclamation point ("!") results in a failed query.  
Not only exclamation, \*,{,}...etc

I do have a artist name like, !!! (chk chk chk) and ke$ha...etc  
When i search chk then it gives the artist name, but when i search only  
exclamation mark then it fails.  
How to force exclamation in search query.\*  
\*  
I tried below code but it didn't work for me,

curl -X PUT '[http://localhost:9200/admin/?pretty=true](http://localhost:9200/admin/?pretty=true)' -d '  
{  
"settings" : {  
"analysis" : {  
"analyzer" : {  
"artist\_analyzer" : {  
"tokenizer" : "standard",  
"filter" : ["standard", "lowercase",  
"artist\_metaphone", "asciifolding"]  
},  
"synonym" : {  
"tokenizer" : "whitespace",  
"filter" : ["synonym"]  
}  
},  
"filter" : {  
"artist\_metaphone" : {  
"type" : "phonetic",  
"encoder" : "metaphone",  
"replace" : false  
},  
"synonym" : {  
"type" : "synonym",  
"synonyms" : [  
"kesha =\> ke$ha",  
"! =\> !!! (chk chk chk)"  
]  
}  
}  
}  
}  
}  
'  
Am i doing wrong something?  
Any help is highly appreciated.

Thanks and regards,  
Vallabh  
On Monday, January 23, 2012 3:03:02 AM UTC+5:30, Nick Hoffman wrote:

> Awesome. Thanks for the explanation and links, Clint! Those're very  
> helpful.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [November 1, 2013, 1:16pm UTC](https://discuss.elastic.co/t/exclamation-point-breaks-field-queries/6460/5 "2013-11-01T13:16:33Z")

</div>

You have to escape Lucene's special characters in a query.

- 
  - && || ! ( ) { } [] ^ " ~ \* ? : \

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![vallabh\_2](https://avatars.discourse-cdn.com/v4/letter/v/7ab992/32.png) [@vallabh\_2](https://discuss.elastic.co/u/vallabh_2)\
**Post date:** [November 1, 2013, 1:30pm UTC](https://discuss.elastic.co/t/exclamation-point-breaks-field-queries/6460/6 "2013-11-01T13:30:37Z")

</div>

Hi Jörg,

Thanks for the quick response.  
But i can not escape this character as i have these characters in my artist  
name list.  
Is there any way from where i can handle this character ?

Thanks and regarsd,  
Vallabh

On Friday, November 1, 2013 6:46:33 PM UTC+5:30, Jörg Prante wrote:

> You have to escape Lucene's special characters in a query.
> 
> - 
> - && || ! ( ) { } ^ " ~ \* ? : \
> 
> Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [November 1, 2013, 2:04pm UTC](https://discuss.elastic.co/t/exclamation-point-breaks-field-queries/6460/7 "2013-11-01T14:04:59Z")

</div>

You provide a correct artist name list for synonym search.

In your queries to ES, you described it as single exclamation mark, you  
have to escape Lucene's special characters.

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)\
**Post date:** [November 1, 2013, 3:07pm UTC](https://discuss.elastic.co/t/exclamation-point-breaks-field-queries/6460/8 "2013-11-01T15:07:32Z")

</div>

Are you trying to support lucene query syntax in your query? If yes, you  
need to escape special characters as Jorg mentioned. If not, you should be  
using a MatchQuery.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Thanks,  
Matt Weber

On Fri, Nov 1, 2013 at 7:04 AM, [joergprante@gmail.com](mailto:joergprante@gmail.com) \<[joergprante@gmail.com](mailto:joergprante@gmail.com)

> wrote:

> You provide a correct artist name list for synonym search.
> 
> In your queries to ES, you described it as single exclamation mark, you  
> have to escape Lucene's special characters.
> 
> Jörg
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![vallabh](https://avatars.discourse-cdn.com/v4/letter/v/e8c25b/32.png) [@vallabh](https://discuss.elastic.co/u/vallabh)\
**Post date:** [November 8, 2013, 7:27am UTC](https://discuss.elastic.co/t/exclamation-point-breaks-field-queries/6460/9 "2013-11-08T07:27:57Z")

</div>

Thanks for the suggestions,  
Yes i am using "elasticsearch-analysis-phonetic/1.6.0" plugin and i think  
it uses lucene.  
I do have a artist name "Death (protopunk band)"  
When i search for "Death (protopunk" including open brace "(" - query fails.  
On the other hand when i search "(protopunk band)" including both open and  
close brace ( ) then it gives expected result.  
I am little confused in elasticsearch query.

On Friday, November 1, 2013 8:37:32 PM UTC+5:30, Matt Weber wrote:

> Are you trying to support lucene query syntax in your query? If yes, you  
> need to escape special characters as Jorg mentioned. If not, you should be  
> using a MatchQuery.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html)
> 
> Thanks,  
> Matt Weber
> 
> On Fri, Nov 1, 2013 at 7:04 AM, [joerg...@gmail.com](mailto:joerg...@gmail.com) \<javascript:\> \<  
> [joerg...@gmail.com](mailto:joerg...@gmail.com) \<javascript:\>\> wrote:
> 
> > You provide a correct artist name list for synonym search.
> > 
> > In your queries to ES, you described it as single exclamation mark, you  
> > have to escape Lucene's special characters.
> > 
> > Jörg
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![vallabh](https://avatars.discourse-cdn.com/v4/letter/v/e8c25b/32.png) [@vallabh](https://discuss.elastic.co/u/vallabh)\
**Post date:** [November 21, 2013, 11:20am UTC](https://discuss.elastic.co/t/exclamation-point-breaks-field-queries/6460/10 "2013-11-21T11:20:03Z")

</div>

Hi Everyone,

I have escape Lucene's special characters and used synonyms search. Now it  
is working as per the requirement.  
But my concern is, i have to change "tokenizer" : "standard", TO  
"tokenizer" : "whitespace", in the code to work synonyms search.

And when i change tokenizer standard to whitespace.  
I am not getting the result for the particaular artist name ie, for Jaz-z  
(include hyphen)

In tokenizer: standard, when i search Jaz z (without hyphen only space), it  
gives me the output as Jay-z  
But now this is not happening in the whitespace case.  
Is there anything where i can use both tokenizer ?

Below is my code,

curl -X PUT '[http://localhost:9200/admin/?pretty=true](http://localhost:9200/admin/?pretty=true)' -d '  
{  
"settings" : {  
"analysis" : {  
"analyzer" : {  
"artist\_analyzer" : {  
"tokenizer" : "whitespace",  
"filter" : ["standard", "lowercase", "synonym",  
"artist\_metaphone", "asciifolding"]  
}  
},  
"filter" : {  
"artist\_metaphone" : {  
"type" : "phonetic",  
"encoder" : "metaphone",  
"replace" : false  
},  
"synonym" : {  
"type" : "synonym",  
"synonyms\_path" :  
"/var/www/html/elasticsearch-master/synonyms.txt"  
}  
}  
}  
}  
}  
'

Any help is very much aprreciated.  
Thanks,

On Friday, November 8, 2013 12:57:57 PM UTC+5:30, Vallabh Bothre wrote:

> Thanks for the suggestions,  
> Yes i am using "elasticsearch-analysis-phonetic/1.6.0" plugin and i think  
> it uses lucene.  
> I do have a artist name "Death (protopunk band)"  
> When i search for "Death (protopunk" including open brace "(" - query  
> fails.  
> On the other hand when i search "(protopunk band)" including both open and  
> close brace ( ) then it gives expected result.  
> I am little confused in elasticsearch query.
> 
> On Friday, November 1, 2013 8:37:32 PM UTC+5:30, Matt Weber wrote:
> 
> > Are you trying to support lucene query syntax in your query? If yes, you  
> > need to escape special characters as Jorg mentioned. If not, you should be  
> > using a MatchQuery.
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html)
> > 
> > Thanks,  
> > Matt Weber
> > 
> > On Fri, Nov 1, 2013 at 7:04 AM, [joerg...@gmail.com](mailto:joerg...@gmail.com) [joerg...@gmail.com](mailto:joerg...@gmail.com)wrote:
> > 
> > > You provide a correct artist name list for synonym search.
> > > 
> > > In your queries to ES, you described it as single exclamation mark, you  
> > > have to escape Lucene's special characters.
> > > 
> > > Jörg
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:05am UTC](https://discuss.elastic.co/t/exclamation-point-breaks-field-queries/6460/11 "2017-07-06T02:05:42Z")

</div>


