# Search on a nested field on multi-indexes, multi-document types throw QueryParsingException

**URL:** <https://discuss.elastic.co/t/search-on-a-nested-field-on-multi-indexes-multi-document-types-throw-queryparsingexception/40269>\
**Category:** Elasticsearch\
**Created:** [January 27, 2016, 5:05pm UTC](https://discuss.elastic.co/t/search-on-a-nested-field-on-multi-indexes-multi-document-types-throw-queryparsingexception/40269 "2016-01-27T17:05:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arnaud\_Babilone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arnaud_babilone/32/7416_2.png) [@Arnaud\_Babilone](https://discuss.elastic.co/u/Arnaud_Babilone)\
**Post date:** [January 27, 2016, 5:05pm UTC](https://discuss.elastic.co/t/search-on-a-nested-field-on-multi-indexes-multi-document-types-throw-queryparsingexception/40269/1 "2016-01-27T17:05:36Z")

</div>

Hi everyone,

I'm facing a strange issue when performing a search on an nested field on multiple indexes, multiple document types.

First of all, we are working on elasticsearch 1.7.3.

My search is on two indexes, which each have one distinct document type inside.  
My nested field is declared **only in one of the two** document type mapping.

The request returns a QueryParsingException telling "[indexname] [nested] failed to find nested object under path [xyz]]"", only for the index which contains the document type **without** the nested field.

If I execute my search request only on the index which contains the document type **with** the nested field, everything works as expected. So this does not seems like a query syntax error.

If I execute a search on the same two indexes, on a field defined only in one of the two document type, but which is not of nested type, everything works as expected.

Thanks in advance for any help,

Sincerely,

A. Babilone

---

<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:** [January 28, 2016, 8:46am UTC](https://discuss.elastic.co/t/search-on-a-nested-field-on-multi-indexes-multi-document-types-throw-queryparsingexception/40269/2 "2016-01-28T08:46:53Z")

</div>

Hi,

Compared to the other queries the nested query is strict when it comes to the existence of a nested field in the mapping and like you're saying it we fail with an error if no nested field can be found.

There is no good work around for this, but what you could try out is to wrap the nested query in an `indices` query:  
[https://www.elastic.co/guide/en/elasticsearch/reference/1.7/query-dsl-indices-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/1.7/query-dsl-indices-query.html)

wrap your `nested` query inside this `indices` query and only execute this query on indices you know have the nested field you're referring to.

In the future we will handle strictness for `nested` query and other queries better: [https://github.com/elastic/elasticsearch/issues/12016](https://github.com/elastic/elasticsearch/issues/12016)

Martijn

---

<div class="post-metadata">

**Author:** ![Arnaud\_Babilone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arnaud_babilone/32/7416_2.png) [@Arnaud\_Babilone](https://discuss.elastic.co/u/Arnaud_Babilone)\
**Post date:** [January 28, 2016, 10:19am UTC](https://discuss.elastic.co/t/search-on-a-nested-field-on-multi-indexes-multi-document-types-throw-queryparsingexception/40269/3 "2016-01-28T10:19:17Z")

</div>

Hi,

Thanks for the quick response!

I'll try to wrap my query in an indice query and see the outcome.

Sincerely,

Arnaud

---

<div class="post-metadata">

**Author:** ![Arnaud\_Babilone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arnaud_babilone/32/7416_2.png) [@Arnaud\_Babilone](https://discuss.elastic.co/u/Arnaud_Babilone)\
**Post date:** [January 29, 2016, 11:30am UTC](https://discuss.elastic.co/t/search-on-a-nested-field-on-multi-indexes-multi-document-types-throw-queryparsingexception/40269/4 "2016-01-29T11:30:38Z")

</div>

Hi,

After some tests everything works now as expected when wrapping query part in indice query when needed.

Thanks again,

Arnaud

---

<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 5, 2017, 11:20pm UTC](https://discuss.elastic.co/t/search-on-a-nested-field-on-multi-indexes-multi-document-types-throw-queryparsingexception/40269/5 "2017-07-05T23:20:23Z")

</div>


