# Elasticsearch \_sql string containing Apostrophe

**URL:** https://discuss.elastic.co/t/elasticsearch-sql-string-containing-apostrophe/221300
**Category:** Elasticsearch
**Created:** [February 27, 2020, 6:17pm UTC](https://discuss.elastic.co/t/elasticsearch-sql-string-containing-apostrophe/221300 "2020-02-27T18:17:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![vikasp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikasp/32/90872_2.png) [@vikasp](https://discuss.elastic.co/u/vikasp)
#### Post date: [February 27, 2020, 6:17pm UTC](https://discuss.elastic.co/t/elasticsearch-sql-string-containing-apostrophe/221300/1 "2020-02-27T18:17:25Z")

</div>

Hi,  
I have a query:

```
GET /test_sql/_search

```

{  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"tenant\_name.keyword": "KNOXVILLE'S CORPORATION"  
}  
}  
]  
}  
}  
}

The above query works fine.  
Now, I try the same thing with \_sql:  
POST /\_sql/translate  
{  
"query": "SELECT \* FROM test\_sql WHERE tenant\_name.keyword = 'KNOXVILLE'S CORPORATION'"  
}  
This doesn't work gives out error:  
"reason": "Unrecognized character escape ''' (code 39)\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@6017995f; line: 2, column: 76]"

I tried various combinations of , " around that string value doesn't work (got a parsing exception).

The below query works:

```
POST _sql?format=txt

```

{  
"query": "SELECT \* FROM test\_sql",  
"filter": {  
"match\_phrase": {  
"tenant\_name": "KNOXVILLE'S CORPORATION"  
}  
}  
}

What are my options to not use filter and include something in the query itself. I am asking this since we have around 80 queries and we wont be able to change all the queries with the added filter.

---

<div class="post-metadata">

### Author: ![matriv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matriv/32/43656_2.png) [@matriv](https://discuss.elastic.co/u/matriv)
#### Post date: [February 28, 2020, 8:57am UTC](https://discuss.elastic.co/t/elasticsearch-sql-string-containing-apostrophe/221300/2 "2020-02-28T08:57:26Z")

</div>

You can escape with 2 single quotes:

```auto
{
"query": "SELECT * FROM test_sql WHERE tenant_name.keyword = 'KNOXVILLE''S CORPORATION'"
}

```

---

<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: [March 27, 2020, 8:57am UTC](https://discuss.elastic.co/t/elasticsearch-sql-string-containing-apostrophe/221300/3 "2020-03-27T08:57:30Z")

</div>

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