# Character escaping

**URL:** <https://discuss.elastic.co/t/character-escaping/9776>\
**Category:** Elasticsearch\
**Created:** [November 21, 2012, 12:30pm UTC](https://discuss.elastic.co/t/character-escaping/9776 "2012-11-21T12:30:15Z")\
**Posts on this page:** 8\
**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:** [November 21, 2012, 12:30pm UTC](https://discuss.elastic.co/t/character-escaping/9776/1 "2012-11-21T12:30:15Z")

</div>

We'd had some issues with characters such as "!" causing queries to fail  
and as pointed out, we should use the "text" query. However, I've since  
noticed that has been deprecated in favor of "match". However, when  
changing to a "match" query, it no longer has escaping. Will "match\_phrase" accomplish  
this?

--

---

<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 21, 2012, 12:35pm UTC](https://discuss.elastic.co/t/character-escaping/9776/2 "2012-11-21T12:35:16Z")

</div>

Hi Brandon

On Wed, 2012-11-21 at 04:30 -0800, Brandon Hilkert wrote:

> We'd had some issues with characters such as "!" causing queries to  
> fail and as pointed out, we should use the "text" query. However, I've  
> since noticed that has been deprecated in favor of "match". However,  
> when changing to a "match" query, it no longer has escaping. Will  
> "match\_phrase" accomplish this?

'match' is the new name for 'text', as 'match\_phrase' is the new name  
for 'text\_phrase'

what do you mean by "match" no longer has escaping?

(the problem with the query\_string/field queries is that they have a  
query mini-language, and any syntax error in that language will stop the  
query from working at all, eg "!" is the NOT operator, which expects  
something to the right of it, but "wow!" would be a syntax error)

--

---

<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:** [November 21, 2012, 12:40pm UTC](https://discuss.elastic.co/t/character-escaping/9776/3 "2012-11-21T12:40:04Z")

</div>

Concretely, a search for "yahoo!" fails with query\_string as expected.  
Using "text" queries it works fine. However, switching to "match", it fails  
for the same escaping reasons as "query\_string". So with "text" being  
deprecated, I'm just wondering what the appropriate query is to use to get  
the behavior of a "text" query that when querying terms like "yahoo!".

On Wed, Nov 21, 2012 at 7:35 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> Hi Brandon
> 
> On Wed, 2012-11-21 at 04:30 -0800, Brandon Hilkert wrote:
> 
> > We'd had some issues with characters such as "!" causing queries to  
> > fail and as pointed out, we should use the "text" query. However, I've  
> > since noticed that has been deprecated in favor of "match". However,  
> > when changing to a "match" query, it no longer has escaping. Will  
> > "match\_phrase" accomplish this?
> 
> 'match' is the new name for 'text', as 'match\_phrase' is the new name  
> for 'text\_phrase'
> 
> what do you mean by "match" no longer has escaping?
> 
> (the problem with the query\_string/field queries is that they have a  
> query mini-language, and any syntax error in that language will stop the  
> query from working at all, eg "!" is the NOT operator, which expects  
> something to the right of it, but "wow!" would be a syntax error)
> 
> --

--

---

<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 21, 2012, 12:46pm UTC](https://discuss.elastic.co/t/character-escaping/9776/4 "2012-11-21T12:46:09Z")

</div>

On Wed, 2012-11-21 at 07:40 -0500, Brandon Hilkert wrote:

> Concretely, a search for "yahoo!" fails with query\_string as expected.  
> Using "text" queries it works fine. However, switching to "match", it  
> fails for the same escaping reasons as "query\_string". So with "text"  
> being deprecated, I'm just wondering what the appropriate query is to  
> use to get the behavior of a "text" query that when querying terms  
> like "yahoo!".

No it doesn't. Why do you think it fails? eg:

curl -XGET '[http://127.0.0.1:9200/test/test/\_search?pretty=1](http://127.0.0.1:9200/test/test/_search?pretty=1)' -d '  
{  
"query" : {  
"match" : {  
"\_all" : "yahoo!"  
}  
}  
}  
'

# [Wed Nov 21 13:45:23 2012] Response:

# {

# "hits" : {

# "hits" : [

# {

# "\_source" : {

# "text" : "yahoo is a search engine"

# },

# "\_score" : 0.15342641,

# "\_index" : "test",

# "\_id" : "ZLN0QHS-RO-zUw7nM8SK-g",

# "\_type" : "test"

# }

# ],

# "max\_score" : 0.15342641,

# "total" : 1

# },

# "timed\_out" : false,

# "\_shards" : {

# "failed" : 0,

# "successful" : 5,

# "total" : 5

# },

# "took" : 2

# }

--

---

<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:** [November 21, 2012, 12:52pm UTC](https://discuss.elastic.co/t/character-escaping/9776/5 "2012-11-21T12:52:16Z")

</div>

Perhaps it's a version thing? We're on 0.19.4?

Tire::Search::SearchRequestFailed (500 :  
{"error":"SearchPhaseExecutionException[Failed to execute phase [query],  
total failure; shardFailures  
{[SyCzadpDTaGKZl4T3zYA0w][meeteor\_development\_users][1]:  
SearchParseException[[development][1]: from[-1],size[-1]: Parse Failure  
[Failed to parse source  
[{"query":{"bool":{"should":[{"match":{"\_all":{"query":"Apple"}}},....  
nested: QueryParsingException[[development] No query registered for  
[match]]; }]","status":500}):

We're also using the Ruby gem Tire for the interface.

On Wed, Nov 21, 2012 at 7:46 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> On Wed, 2012-11-21 at 07:40 -0500, Brandon Hilkert wrote:
> 
> > Concretely, a search for "yahoo!" fails with query\_string as expected.  
> > Using "text" queries it works fine. However, switching to "match", it  
> > fails for the same escaping reasons as "query\_string". So with "text"  
> > being deprecated, I'm just wondering what the appropriate query is to  
> > use to get the behavior of a "text" query that when querying terms  
> > like "yahoo!".
> 
> No it doesn't. Why do you think it fails? eg:
> 
> curl -XGET '[http://127.0.0.1:9200/test/test/\_search?pretty=1](http://127.0.0.1:9200/test/test/_search?pretty=1)' -d '  
> {  
> "query" : {  
> "match" : {  
> "\_all" : "yahoo!"  
> }  
> }  
> }  
> '
> 
> # [Wed Nov 21 13:45:23 2012] Response:
> 
> # {
> 
> # "hits" : {
> 
> # "hits" : [
> 
> # {
> 
> # "\_source" : {
> 
> # "text" : "yahoo is a search engine"
> 
> # },
> 
> # "\_score" : 0.15342641,
> 
> # "\_index" : "test",
> 
> # "\_id" : "ZLN0QHS-RO-zUw7nM8SK-g",
> 
> # "\_type" : "test"
> 
> # }
> 
> # ],
> 
> # "max\_score" : 0.15342641,
> 
> # "total" : 1
> 
> # },
> 
> # "timed\_out" : false,
> 
> # "\_shards" : {
> 
> # "failed" : 0,
> 
> # "successful" : 5,
> 
> # "total" : 5
> 
> # },
> 
> # "took" : 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 21, 2012, 12:54pm UTC](https://discuss.elastic.co/t/character-escaping/9776/6 "2012-11-21T12:54:45Z")

</div>

On Wed, 2012-11-21 at 07:52 -0500, Brandon Hilkert wrote:

> Perhaps it's a version thing? We're on 0.19.4?

Ah, that's pre "match" query 🙂

You're still using "text"

clint

> Tire::Search::SearchRequestFailed (500 :  
> {"error":"SearchPhaseExecutionException[Failed to execute phase  
> [query], total failure; shardFailures  
> {[SyCzadpDTaGKZl4T3zYA0w][meeteor\_development\_users][1]:  
> SearchParseException[[development][1]: from[-1],size[-1]: Parse  
> Failure [Failed to parse source [{"query":{"bool":{"should  
> ":[{"match":{"\_all":{"query":"Apple"}}},....
> 
> nested: QueryParsingException[[development] No query registered for  
> [match]]; }]","status":500}):
> 
> We're also using the Ruby gem Tire for the interface.
> 
> On Wed, Nov 21, 2012 at 7:46 AM, Clinton Gormley  
> [clint@traveljury.com](mailto:clint@traveljury.com) wrote:  
> On Wed, 2012-11-21 at 07:40 -0500, Brandon Hilkert wrote:  
> \> Concretely, a search for "yahoo!" fails with query\_string as  
> expected.  
> \> Using "text" queries it works fine. However, switching to  
> "match", it  
> \> fails for the same escaping reasons as "query\_string". So  
> with "text"  
> \> being deprecated, I'm just wondering what the appropriate  
> query is to  
> \> use to get the behavior of a "text" query that when querying  
> terms  
> \> like "yahoo!".
> 
> ```
> No it doesn't. Why do you think it fails? eg:
>     
> curl -XGET 'http://127.0.0.1:9200/test/test/_search?pretty=1'
> -d '
> {
> "query" : {
> "match" : {
> "_all" : "yahoo!"
> }
> }
> }
> '
>     
> # [Wed Nov 21 13:45:23 2012] Response:
> # {
> # "hits" : {
> # "hits" : [
> # {
> # "_source" : {
> # "text" : "yahoo is a search engine"
> # },
> # "_score" : 0.15342641,
> # "_index" : "test",
> # "_id" : "ZLN0QHS-RO-zUw7nM8SK-g",
> # "_type" : "test"
> # }
> # ],
> # "max_score" : 0.15342641,
> # "total" : 1
> # },
> # "timed_out" : false,
> # "_shards" : {
> # "failed" : 0,
> # "successful" : 5,
> # "total" : 5
> # },
> # "took" : 2
> # }
>     
>     
> --
> 
> ```
> 
> --

--

---

<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:** [November 21, 2012, 12:56pm UTC](https://discuss.elastic.co/t/character-escaping/9776/7 "2012-11-21T12:56:35Z")

</div>

Hahaha ok. Thanks!

On Nov 21, 2012, at 7:54 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com) wrote:

> On Wed, 2012-11-21 at 07:52 -0500, Brandon Hilkert wrote:
> 
> > Perhaps it's a version thing? We're on 0.19.4?
> 
> Ah, that's pre "match" query 🙂
> 
> You're still using "text"
> 
> clint
> 
> > Tire::Search::SearchRequestFailed (500 :  
> > {"error":"SearchPhaseExecutionException[Failed to execute phase  
> > [query], total failure; shardFailures  
> > {[SyCzadpDTaGKZl4T3zYA0w][meeteor\_development\_users][1]:  
> > SearchParseException[[development][1]: from[-1],size[-1]: Parse  
> > Failure [Failed to parse source [{"query":{"bool":{"should  
> > ":[{"match":{"\_all":{"query":"Apple"}}},....
> > 
> > nested: QueryParsingException[[development] No query registered for  
> > [match]]; }]","status":500}):
> > 
> > We're also using the Ruby gem Tire for the interface.
> > 
> > On Wed, Nov 21, 2012 at 7:46 AM, Clinton Gormley  
> > [clint@traveljury.com](mailto:clint@traveljury.com) wrote:  
> > On Wed, 2012-11-21 at 07:40 -0500, Brandon Hilkert wrote:
> > 
> > > Concretely, a search for "yahoo!" fails with query\_string as  
> > > expected.  
> > > Using "text" queries it works fine. However, switching to  
> > > "match", it  
> > > fails for the same escaping reasons as "query\_string". So  
> > > with "text"  
> > > being deprecated, I'm just wondering what the appropriate  
> > > query is to  
> > > use to get the behavior of a "text" query that when querying  
> > > terms  
> > > like "yahoo!".
> > 
> > ```
> > No it doesn't. Why do you think it fails? eg:
> > 
> > curl -XGET 'http://127.0.0.1:9200/test/test/_search?pretty=1'
> > -d '
> > {
> > "query" : {
> > "match" : {
> > "_all" : "yahoo!"
> > }
> > }
> > }
> > '
> > 
> > # [Wed Nov 21 13:45:23 2012] Response:
> > # {
> > # "hits" : {
> > # "hits" : [
> > # {
> > # "_source" : {
> > # "text" : "yahoo is a search engine"
> > # },
> > # "_score" : 0.15342641,
> > # "_index" : "test",
> > # "_id" : "ZLN0QHS-RO-zUw7nM8SK-g",
> > # "_type" : "test"
> > # }
> > # ],
> > # "max_score" : 0.15342641,
> > # "total" : 1
> > # },
> > # "timed_out" : false,
> > # "_shards" : {
> > # "failed" : 0,
> > # "successful" : 5,
> > # "total" : 5
> > # },
> > # "took" : 2
> > # }
> > 
> > --
> > 
> > ```
> > 
> > --
> 
> --

--

---

<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:03am UTC](https://discuss.elastic.co/t/character-escaping/9776/8 "2017-07-06T03:03:23Z")

</div>


