# Add nested document from another index

**URL:** https://discuss.elastic.co/t/add-nested-document-from-another-index/120744
**Category:** Logstash
**Created:** [February 21, 2018, 12:14am UTC](https://discuss.elastic.co/t/add-nested-document-from-another-index/120744 "2018-02-21T00:14:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Baljeet\_Dogra](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@Baljeet\_Dogra](https://discuss.elastic.co/u/Baljeet_Dogra)
#### Post date: [February 21, 2018, 12:14am UTC](https://discuss.elastic.co/t/add-nested-document-from-another-index/120744/1 "2018-02-21T00:14:57Z")

</div>

I have a requirement to lookup another index in elasticsearch and when the document is found I need to embed the entire document in another document in another index.

employee-index (assume already populated)  
{ \_id: emp01, name: David, role: admin}  
{ \_id: emp02, name: John, role: developer, country: USA}  
{ \_id: emp03, name: Manoj, role: marketing, type: external}

salary-index  
salary data has employee id  
$10000, emp01  
$14000, emp02  
$17000, emp03

When inserting salary data I need to lookup employee index using the id which I can do using the elasticsearch plugin. But how do I fetch the entire document and nest it in the salary document without having to fetch individual fields. I do not want to use fields because the document schema may be different.

Intended document in salary index where employee is nested type

{  
\_id: 1,  
salary: $10000,  
employee : { \_id: emp01, name: David, role: admin}  
}

{  
\_id: 2,  
salary: $14000,  
employee : { \_id: emp02, name: John, role: developer, country: USA }  
}

---

<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: [March 21, 2018, 12:15am UTC](https://discuss.elastic.co/t/add-nested-document-from-another-index/120744/2 "2018-03-21T00:15:05Z")

</div>

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