# How to query multiple indexes in ElasticSearch 5.6 when they have different parent-child mappings?

**URL:** https://discuss.elastic.co/t/how-to-query-multiple-indexes-in-elasticsearch-5-6-when-they-have-different-parent-child-mappings/105300
**Category:** Elasticsearch
**Created:** [October 25, 2017, 9:11pm UTC](https://discuss.elastic.co/t/how-to-query-multiple-indexes-in-elasticsearch-5-6-when-they-have-different-parent-child-mappings/105300 "2017-10-25T21:11:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sclaggett](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@sclaggett](https://discuss.elastic.co/u/sclaggett)
#### Post date: [October 25, 2017, 9:11pm UTC](https://discuss.elastic.co/t/how-to-query-multiple-indexes-in-elasticsearch-5-6-when-they-have-different-parent-child-mappings/105300/1 "2017-10-25T21:11:17Z")

</div>

We're attempting to retrieve results from several different Elasticsearch indexes and sort them by a common field. The way we're approaching this is to create a boolean query that is composed of multiple _should_ statements with the first _should_ statement selecting items from index A, the second from index B, etc.

The complication is that each index has its own parent-child relationships that have been implemented using the new [join](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/parent-join.html) datatype. Some of the _should_ statements involve _has\_parent_ queries which work on the intended index but fail on the others because they lack the same relationships:

> query\_shard\_exception: [has\_child] join field [\_docJoin] doesn't hold [childEffort] as a child

One solution is to combine all of the parent-child relationships and use the same _join_ datatype across all indexes. This prevents the _has\_child_ query from failing but seems a bit confusing and hacky. Is there a cleaner solution to this problem?

Thanks,  
Shane

---

<div class="post-metadata">

### Author: ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)
#### Post date: [October 27, 2017, 9:29am UTC](https://discuss.elastic.co/t/how-to-query-multiple-indexes-in-elasticsearch-5-6-when-they-have-different-parent-child-mappings/105300/2 "2017-10-27T09:29:09Z")

</div>

You can try to use the multi search api and create a search request for each index with the correct `has_child` query. You do endup then with seperate search results.

You can also create a single search request with a `bool` query that old each `has_child` query as a should clause and use the `ignore_unmapped` parameter on the `has_child` query:  
[https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-has-child-query.html#\_ignore\_unmapped](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-has-child-query.html#_ignore_unmapped)

---

<div class="post-metadata">

### Author: ![sclaggett](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@sclaggett](https://discuss.elastic.co/u/sclaggett)
#### Post date: [October 31, 2017, 5:47pm UTC](https://discuss.elastic.co/t/how-to-query-multiple-indexes-in-elasticsearch-5-6-when-they-have-different-parent-child-mappings/105300/3 "2017-10-31T17:47:00Z")

</div>

Thank you Martijn, the `ignore_unmapped` field solved the problem!

---

<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: [November 28, 2017, 5:47pm UTC](https://discuss.elastic.co/t/how-to-query-multiple-indexes-in-elasticsearch-5-6-when-they-have-different-parent-child-mappings/105300/4 "2017-11-28T17:47:46Z")

</div>

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