# Load Data from other index without searching in this index

**URL:** <https://discuss.elastic.co/t/load-data-from-other-index-without-searching-in-this-index/220412>\
**Category:** Elasticsearch\
**Created:** [February 21, 2020, 4:04pm UTC](https://discuss.elastic.co/t/load-data-from-other-index-without-searching-in-this-index/220412 "2020-02-21T16:04:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nerd2000](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@nerd2000](https://discuss.elastic.co/u/nerd2000)\
**Post date:** [February 21, 2020, 4:04pm UTC](https://discuss.elastic.co/t/load-data-from-other-index-without-searching-in-this-index/220412/1 "2020-02-21T16:04:44Z")

</div>

Hi,

Let's say that I have this 2 indices:  
`{ "films": { "mappings": { "properties": { "id": {"type": long}, "title": {"type": keyword}, "release_date": {"type": date}, "songs": {"id": {"type": long}} } } } }`

`{ "songs": { "mappings": { "properties": { "id": {"type": long}, "name": {"type": keyword}, "type": {"type": keyword}, "films": {"id": {"type": long}} } } } }`

Is there a way I could search on the `films` index and load automatically the corresponding songs in **a single request**?  
It looks like a basic SQL JOIN query which I know is

> prohibitively expensive

but it's not really what I want to do. I don't want to search on both indices, only one at a time, but load the corresponding data from the other index.

In some ORMs, this is call eager loading, but I don't think that eager loading means the same thing in elasticsearch.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 24, 2020, 9:33am UTC](https://discuss.elastic.co/t/load-data-from-other-index-without-searching-in-this-index/220412/2 "2020-02-24T09:33:04Z")

</div>

if this is stored in two indices, then you have to execute two queries.

You could try to store such data in a single index or even in a single document. Like one `film` doucment that also contains all the songs (or at least the names), if that works for you. This way you could circumvent all the double querying be remodeling your data.

---

<div class="post-metadata">

**Author:** ![nerd2000](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@nerd2000](https://discuss.elastic.co/u/nerd2000)\
**Post date:** [February 24, 2020, 9:55am UTC](https://discuss.elastic.co/t/load-data-from-other-index-without-searching-in-this-index/220412/3 "2020-02-24T09:55:15Z")

</div>

> if this is stored in two indices, then you have to execute two queries.

This kind of answers my question. I was trying to load data from 2 indices in one query, so at least I understand that it is not possible.

The things is, the data in each index are going to be updated pretty frequently and independently from each other. So, I would say that storing in one index could be fine but not in one document i guess.

So let's say I'm storing these 2 mappings in one index, would a Parent-Child relationship be a good way to linked them?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 24, 2020, 10:54am UTC](https://discuss.elastic.co/t/load-data-from-other-index-without-searching-in-this-index/220412/4 "2020-02-24T10:54:01Z")

</div>

> So let's say I'm storing these 2 mappings in one index, would a Parent-Child relationship be a good way to linked them?

Yes, the join datatype (got renamed over the last years) is a good idea then.

---

<div class="post-metadata">

**Author:** ![nerd2000](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@nerd2000](https://discuss.elastic.co/u/nerd2000)\
**Post date:** [February 24, 2020, 11:05am UTC](https://discuss.elastic.co/t/load-data-from-other-index-without-searching-in-this-index/220412/5 "2020-02-24T11:05:07Z")

</div>

> So let's say I'm storing these 2 mappings in one index, would a Parent-Child relationship be a good way to linked them?

Actually, it's not what I'm looking for.

> An element can have multiple children but only one parent.

> **[Join field type | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/parent-join.html#_parent_join_restrictions)**

In my scenario, I want to be able to look for every songs in a film and every films where a song appears. So I would need something like a SQL Many to Many relation, which the join datatype can't do apparently.

Maybe this could be possible with an aggregation?

---

<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 23, 2020, 11:05am UTC](https://discuss.elastic.co/t/load-data-from-other-index-without-searching-in-this-index/220412/6 "2020-03-23T11:05:08Z")

</div>

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