# How to query like mysql?

**URL:** <https://discuss.elastic.co/t/how-to-query-like-mysql/60873>\
**Category:** Elasticsearch\
**Created:** [September 19, 2016, 11:35am UTC](https://discuss.elastic.co/t/how-to-query-like-mysql/60873 "2016-09-19T11:35:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![arsenepark](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@arsenepark](https://discuss.elastic.co/u/arsenepark)\
**Post date:** [September 19, 2016, 11:35am UTC](https://discuss.elastic.co/t/how-to-query-like-mysql/60873/1 "2016-09-19T11:35:36Z")

</div>

hey, there,

I have the following data:  
{  
"my\_key": "hello world"  
}

now, I have 2 requirements:

1. I want to search exactly the string : "hello world", like mysql "="
2. I want to search "llo wor", like mysql " like '%llo wor%'' "

How can I use ES to do this?

Thanks,  
Dennis

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 19, 2016, 11:56am UTC](https://discuss.elastic.co/t/how-to-query-like-mysql/60873/2 "2016-09-19T11:56:57Z")

</div>

Please format your code using `</>` icon. It will make your post more readable.

You need to understand how all this works.  
By default, when you index `hello world`, you basically create 2 entries in the inverted index: `hello`, `world`.  
You can of course [use phrase search](https://www.elastic.co/guide/en/elasticsearch/guide/current/phrase-matching.html) for your first question.  
For the second question, I'd really recommend not using any wildcard query but better index your data as you will query them.

Typically [using ngrams](https://www.elastic.co/guide/en/elasticsearch/guide/2.x/_ngrams_for_partial_matching.html), you can index here something like `hel`, `ell`, `llo`, `hell`, `ello`and `hello`. Then searching for `llo` will match.

Hope this helps

---

<div class="post-metadata">

**Author:** ![arsenepark](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@arsenepark](https://discuss.elastic.co/u/arsenepark)\
**Post date:** [September 19, 2016, 3:34pm UTC](https://discuss.elastic.co/t/how-to-query-like-mysql/60873/3 "2016-09-19T15:34:35Z")

</div>

Thank you, David ^-^

---

<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 5, 2017, 10:19pm UTC](https://discuss.elastic.co/t/how-to-query-like-mysql/60873/4 "2017-07-05T22:19:06Z")

</div>


