# Joining two documents into one single document in Elastic 6.3?

**URL:** https://discuss.elastic.co/t/joining-two-documents-into-one-single-document-in-elastic-6-3/136568
**Category:** Elasticsearch
**Created:** [June 19, 2018, 8:23pm UTC](https://discuss.elastic.co/t/joining-two-documents-into-one-single-document-in-elastic-6-3/136568 "2018-06-19T20:23:23Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Suryatejreddy](https://avatars.discourse-cdn.com/v4/letter/s/e9bcb4/32.png) [@Suryatejreddy](https://discuss.elastic.co/u/Suryatejreddy)
#### Post date: [June 19, 2018, 8:23pm UTC](https://discuss.elastic.co/t/joining-two-documents-into-one-single-document-in-elastic-6-3/136568/1 "2018-06-19T20:23:24Z")

</div>

Can we join two documents into one single document(nested) in Elastic 6.3?

Like.. I have student and department as two documents.

Can I add department document as a nested array in student document into some other index?

Eg: Student{.....department[....]}

thanks,  
Surya

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [June 19, 2018, 8:35pm UTC](https://discuss.elastic.co/t/joining-two-documents-into-one-single-document-in-elastic-6-3/136568/2 "2018-06-19T20:35:41Z")

</div>

It is possible to do with a logstash configuration that consists of [elasticsearch input](https://www.elastic.co/guide/en/logstash/6.3/plugins-inputs-elasticsearch.html) (to read students), [elasticsearch filter](https://www.elastic.co/guide/en/logstash/6.3/plugins-filters-elasticsearch.html) (to lookup departments), and [elasticsearch output](https://www.elastic.co/guide/en/logstash/6.3/plugins-outputs-elasticsearch.html) (to index the joined records back into elasticsearch).

---

<div class="post-metadata">

### Author: ![Suryatejreddy](https://avatars.discourse-cdn.com/v4/letter/s/e9bcb4/32.png) [@Suryatejreddy](https://discuss.elastic.co/u/Suryatejreddy)
#### Post date: [June 20, 2018, 2:07pm UTC](https://discuss.elastic.co/t/joining-two-documents-into-one-single-document-in-elastic-6-3/136568/3 "2018-06-20T14:07:01Z")

</div>

Thanks for the response, So using logstash can we make a document to be nested in some other document? Can this be done inside logstash filter?

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [June 21, 2018, 2:31pm UTC](https://discuss.elastic.co/t/joining-two-documents-into-one-single-document-in-elastic-6-3/136568/4 "2018-06-21T14:31:50Z")

</div>

> So using logstash can we make a document to be nested in some other document?

Yes, you define the document as nested in the mapping, and then you use logstash to create a source that would match this nested structure.

---

<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 19, 2018, 2:31pm UTC](https://discuss.elastic.co/t/joining-two-documents-into-one-single-document-in-elastic-6-3/136568/5 "2018-07-19T14:31:56Z")

</div>

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