# Convert MySQL query to Elasticsearch query

**URL:** https://discuss.elastic.co/t/convert-mysql-query-to-elasticsearch-query/133509
**Category:** Elasticsearch
**Created:** [May 28, 2018, 9:39am UTC](https://discuss.elastic.co/t/convert-mysql-query-to-elasticsearch-query/133509 "2018-05-28T09:39:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![newnewb](https://avatars.discourse-cdn.com/v4/letter/n/c37758/32.png) [@newnewb](https://discuss.elastic.co/u/newnewb)
#### Post date: [May 28, 2018, 9:39am UTC](https://discuss.elastic.co/t/convert-mysql-query-to-elasticsearch-query/133509/1 "2018-05-28T09:39:20Z")

</div>

Heello,

We're considering moving to ELK, so I just started learning ES and I need to convert our MySQL query into Elasticsearch so we can benchmark the performance of both, but everything's still a bit confusing..

Can anyone help me convert this simple query into an ES query?

```
SELECT count(*)
	FROM (
		SELECT DISTINCT word_id
		FROM words_list
		WHERE domain_id = 58 AND type_id IN (5, 3)
	)as our_data
	JOIN (
		SELECT word_id 
		FROM words_list
		WHERE type_id = 5
	) as other_data
	ON our_data.word_id=other_data.word_id
	;
```

---

<div class="post-metadata">

### Author: ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)
#### Post date: [May 28, 2018, 5:52pm UTC](https://discuss.elastic.co/t/convert-mysql-query-to-elasticsearch-query/133509/2 "2018-05-28T17:52:25Z")

</div>

Elasticsearch does not performs subselects nor joins like that. At best, you can do join-like queries using nested or parent/child mappings, but that also has a few caveats.

The recommended is to denormalize data in Elasticsearch.

---

<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: [June 25, 2018, 5:52pm UTC](https://discuss.elastic.co/t/convert-mysql-query-to-elasticsearch-query/133509/3 "2018-06-25T17:52:28Z")

</div>

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