# How to get the combined data from two different document?

**URL:** <https://discuss.elastic.co/t/how-to-get-the-combined-data-from-two-different-document/5792>\
**Category:** Elasticsearch\
**Created:** [November 7, 2011, 12:14pm UTC](https://discuss.elastic.co/t/how-to-get-the-combined-data-from-two-different-document/5792 "2011-11-07T12:14:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![narinder\_izap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/narinder_izap/32/803_2.png) [@narinder\_izap](https://discuss.elastic.co/u/narinder_izap)\
**Post date:** [November 7, 2011, 12:14pm UTC](https://discuss.elastic.co/t/how-to-get-the-combined-data-from-two-different-document/5792/1 "2011-11-07T12:14:08Z")

</div>

Hi there,

I have a situation where i need to apply some kind of join in the query,  
like fetching some data from one document and some from other based on some  
common attribute value. As for example the two documents are:  
_type :user_

title:"abc",  
id:"1",  
city:"aaa",  
DOB:"10-10-90",  
fan\_id:"10"

and the second document will be  
_type : relation_  
\*  
\*  
\*  
\*  
fan\_of :"10",  
"time\_created":"398769978"

now i have to get the users from document type:user whose fan\_of = fan\_id  
and sort the documents by second document 's time\_created. Can anyone help  
me??

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [November 7, 2011, 3:53pm UTC](https://discuss.elastic.co/t/how-to-get-the-combined-data-from-two-different-document/5792/2 "2011-11-07T15:53:45Z")

</div>

Maybe top\_children query could help:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Peter.

On Nov 7, 1:14 pm, Narinder Kaur [narinder.k...@izap.in](mailto:narinder.k...@izap.in) wrote:

> Hi there,
> 
> I have a situation where i need to apply some kind of join in the query,  
> like fetching some data from one document and some from other based on some  
> common attribute value. As for example the two documents are:  
> _type :user_
> 
> title:"abc",  
> id:"1",  
> city:"aaa",  
> DOB:"10-10-90",  
> fan\_id:"10"
> 
> and the second document will be  
> _type : relation_  
> \*  
> \*  
> \*  
> \*  
> fan\_of :"10",  
> "time\_created":"398769978"
> 
> now i have to get the users from document type:user whose fan\_of = fan\_id  
> and sort the documents by second document 's time\_created. Can anyone help  
> me??

---

<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, 3:49am UTC](https://discuss.elastic.co/t/how-to-get-the-combined-data-from-two-different-document/5792/3 "2017-07-06T03:49:45Z")

</div>

Closed on July 6, 2017, 3:49am UTC


