# Error using nested query: "child query must only match non-parent docs"

**URL:** <https://discuss.elastic.co/t/error-using-nested-query-child-query-must-only-match-non-parent-docs/67815>\
**Category:** Elasticsearch\
**Created:** [December 1, 2016, 11:52pm UTC](https://discuss.elastic.co/t/error-using-nested-query-child-query-must-only-match-non-parent-docs/67815 "2016-12-01T23:52:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpblair](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jpblair](https://discuss.elastic.co/u/jpblair)\
**Post date:** [December 1, 2016, 11:52pm UTC](https://discuss.elastic.co/t/error-using-nested-query-child-query-must-only-match-non-parent-docs/67815/1 "2016-12-01T23:52:05Z")

</div>

I'm trying to run a nested query in filter context, but when I do, I get the error below. I only get this error in 2.x. In 1.x, it works as expected (I'm currently migrating from 1.x to 2.x).

The nested query references the full field names (ie, is prefixed with the name of the top-level nested field). I did so following the response I received on another thread [here](https://discuss.elastic.co/t/querying-on-a-subobject-field-within-a-nested-object/65533). Strangely, when I remove that prefix, it also appears to work.

```
{  
   "error":{  
      "root_cause":[  
         {  
            "type":"illegal_state_exception",
            "reason":"child query must only match non-parent docs, but parent docID=332 matched childScorer=class org.apache.lucene.search.ConjunctionScorer"
         }
      ]
   }
}

```

What am I doing wrong? I'm not even sure what this error means. It seems to be a low-level Lucene error.

Thanks.

---

<div class="post-metadata">

**Author:** ![jpblair](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jpblair](https://discuss.elastic.co/u/jpblair)\
**Post date:** [December 9, 2016, 7:33pm UTC](https://discuss.elastic.co/t/error-using-nested-query-child-query-must-only-match-non-parent-docs/67815/2 "2016-12-09T19:33:01Z")

</div>

Turns out I had the `nested` filter wrapped in another `nested` filter, and that was the reason for the problem. Sorry for the false alarm.

---

<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:** [January 6, 2017, 7:33pm UTC](https://discuss.elastic.co/t/error-using-nested-query-child-query-must-only-match-non-parent-docs/67815/3 "2017-01-06T19:33:04Z")

</div>

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