# How to create query to join two types

**URL:** <https://discuss.elastic.co/t/how-to-create-query-to-join-two-types/80467>\
**Category:** Elasticsearch\
**Created:** [March 29, 2017, 11:16am UTC](https://discuss.elastic.co/t/how-to-create-query-to-join-two-types/80467 "2017-03-29T11:16:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tinhhp](https://avatars.discourse-cdn.com/v4/letter/t/dfb087/32.png) [@tinhhp](https://discuss.elastic.co/u/tinhhp)\
**Post date:** [March 29, 2017, 11:16am UTC](https://discuss.elastic.co/t/how-to-create-query-to-join-two-types/80467/1 "2017-03-29T11:16:04Z")

</div>

I have two types as below:  
type\_user {  
user\_id,  
type\_id  
}  
//one user\_id has many type\_id  
row\_data {  
row\_id,  
type\_id  
}  
//row\_data.type\_id = type\_user.type\_id  
I want to get all rows in row\_data by join type\_user and row\_data with parameter is user\_id.How to write query DSL? Anyone can help me for this problem?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [March 29, 2017, 3:30pm UTC](https://discuss.elastic.co/t/how-to-create-query-to-join-two-types/80467/2 "2017-03-29T15:30:18Z")

</div>

Elasticsearch does not support arbitrary joins. You would need to think about how best to model your data, the most commont options are to denormalize your data entirely, use `nested` documents, or Elasticsearch`s support for parent/child relations as a last resort.

---

<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:** [April 26, 2017, 3:30pm UTC](https://discuss.elastic.co/t/how-to-create-query-to-join-two-types/80467/3 "2017-04-26T15:30:27Z")

</div>

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