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

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 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

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

Thank you Martijn, the ignore_unmapped field solved the problem!

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