# Merge data fer two indices with foreign key

**URL:** https://discuss.elastic.co/t/merge-data-fer-two-indices-with-foreign-key/116863
**Category:** Elasticsearch
**Created:** [January 24, 2018, 12:17pm UTC](https://discuss.elastic.co/t/merge-data-fer-two-indices-with-foreign-key/116863 "2018-01-24T12:17:11Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![aneesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aneesh/32/37819_2.png) [@aneesh](https://discuss.elastic.co/u/aneesh)
#### Post date: [January 25, 2018, 4:10am UTC](https://discuss.elastic.co/t/merge-data-fer-two-indices-with-foreign-key/116863/3 "2018-01-25T04:10:57Z")

</div>

```
Student
=======
{
	"StudentId":1,
	"StudentName":"abc"
}

Subject
=======
{
	"SubjectId":101,
	"SubjectName":"English"
},
{
	"SubjectId":102,
	"SubjectName":"Science"
}

SubjectAssigned
===============
{
	"SubjectId":101,
	"StudentId":1
},
{
	"SubjectId":102,
	"StudentId":1
}

Student+SubjectAssigned (Need something like this as result)
=======================

{
	"StudentId":1,
	"StudentName":"abc"
	"Subjects":[
		{
			"SubjectId":101,
			"SubjectName":"English"
		},
		{
			"SubjectId":102,
			"SubjectName":"Science"
		}
	]
}
```

---

_[View the full topic](https://discuss.elastic.co/t/merge-data-fer-two-indices-with-foreign-key/116863)._
