# Joins using internal queries

**URL:** https://discuss.elastic.co/t/joins-using-internal-queries/3381
**Category:** Elasticsearch
**Created:** [September 28, 2010, 9:40pm UTC](https://discuss.elastic.co/t/joins-using-internal-queries/3381 "2010-09-28T21:40:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![talsalmona](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/talsalmona/32/3316_2.png) [@talsalmona](https://discuss.elastic.co/u/talsalmona)
#### Post date: [September 28, 2010, 9:40pm UTC](https://discuss.elastic.co/t/joins-using-internal-queries/3381/1 "2010-09-28T21:40:15Z")

</div>

Hi Shay,

Do you have plans to add support for "emulating" joins on  
ElasticSearch?  
What I mean is being able to define something like a script field that  
would actually do an additional get to fetch a child document and  
embed it in the result as if it was part of the parent doc.  
I think this a very common scenario and I've seen some questions about  
it in the forum.  
Of course this could be done on the client side but I think it would  
be nicer doing it inside ElasticSearch.

{  
"query" : {  
...  
},  
"script\_fields" : {  
"joined\_doc" : {  
"by\_id" : {  
"index": "other\_index"  
"type": "other\_type"  
"id": "doc['my\_field\_name'].value"  
}  
}  
}  
}

Thanks,  
Tal

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [September 28, 2010, 9:42pm UTC](https://discuss.elastic.co/t/joins-using-internal-queries/3381/2 "2010-09-28T21:42:43Z")

</div>

Yea, I do have some ideas on how to implement it. Get is a good high level  
view of how it might work, but its much different under the covers. Going to  
play with my idea on how to solve it in the next couple of weeks, need to  
validate it first....

-shay.banon

On Tue, Sep 28, 2010 at 11:40 PM, Tal [talsalmona@gmail.com](mailto:talsalmona@gmail.com) wrote:

> Hi Shay,
> 
> Do you have plans to add support for "emulating" joins on  
> Elasticsearch?  
> What I mean is being able to define something like a script field that  
> would actually do an additional get to fetch a child document and  
> embed it in the result as if it was part of the parent doc.  
> I think this a very common scenario and I've seen some questions about  
> it in the forum.  
> Of course this could be done on the client side but I think it would  
> be nicer doing it inside Elasticsearch.
> 
> {  
> "query" : {  
> ...  
> },  
> "script\_fields" : {  
> "joined\_doc" : {  
> "by\_id" : {  
> "index": "other\_index"  
> "type": "other\_type"  
> "id": "doc['my\_field\_name'].value"  
> }  
> }  
> }  
> }
> 
> Thanks,  
> Tal

---

<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, 4:18am UTC](https://discuss.elastic.co/t/joins-using-internal-queries/3381/3 "2017-07-06T04:18:46Z")

</div>


