# 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:** 5
**Page:** 1

<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 24, 2018, 12:17pm UTC](https://discuss.elastic.co/t/merge-data-fer-two-indices-with-foreign-key/116863/1 "2018-01-24T12:17:11Z")

</div>

Hi,  
Can I get the merged data from two different indices?  
For example: Index1 : Name, Id , Type  
Index2: Type, TypeData1  
Type, TypeData2  
I want data to be returned in single query like Name,Id,Type:[TypeData1,TypeData2].  
Basically, same operation a n inner join does in sql or join in Linq.

Thanks in Advance,,  
Regards,  
Aneesh

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 24, 2018, 12:46pm UTC](https://discuss.elastic.co/t/merge-data-fer-two-indices-with-foreign-key/116863/2 "2018-01-24T12:46:34Z")

</div>

Elasticsearch does not support join queries as per say.

What is the end user need for that? Could you describe what your model is with some basic json documents?

---

<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"
		}
	]
}
```

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 25, 2018, 9:23am UTC](https://discuss.elastic.co/t/merge-data-fer-two-indices-with-foreign-key/116863/4 "2018-01-25T09:23:18Z")

</div>

Great. In your use case, what people are going to search for? Students?

Then index:

```auto
PUT students/doc/1
{
	"StudentId":1,
	"StudentName":"abc"
	"Subjects":[
		{
			"SubjectId":101,
			"SubjectName":"English"
		},
		{
			"SubjectId":102,
			"SubjectName":"Science"
		}
	]
}

```

And you're done.

Do you want to search for assignations?  
Then index:

```auto
PUT assignations/doc/102-1
{
    "SubjectId":102,
    "SubjectName":"Science",
    "StudentId": 1,
    "StudentName": "abc"
}

```

For example.

---

<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: [February 22, 2018, 9:24am UTC](https://discuss.elastic.co/t/merge-data-fer-two-indices-with-foreign-key/116863/5 "2018-02-22T09:24:02Z")

</div>

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