# Parent Id query problem

**URL:** <https://discuss.elastic.co/t/parent-id-query-problem/70073>\
**Category:** Elasticsearch\
**Created:** [December 27, 2016, 2:26pm UTC](https://discuss.elastic.co/t/parent-id-query-problem/70073 "2016-12-27T14:26:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![theredcat](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theredcat/32/14164_2.png) [@theredcat](https://discuss.elastic.co/u/theredcat)\
**Post date:** [December 27, 2016, 2:26pm UTC](https://discuss.elastic.co/t/parent-id-query-problem/70073/1 "2016-12-27T14:26:30Z")

</div>

Hi!

I have a problem with a test that i've run with Kibana and ES 5.1

If I have understood the [doc](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-parent-id-query.html) correctly, those 2 requests should return the same result, but it's not the case :

```
GET /gangs/_search
{
  "query": {
    "parent_id" : {
      "type" : "gang",
      "id" : "gang1"
    }
  }
}

GET /gangs/_search
{
  "query": {
    "has_parent": {
      "parent_type": "gang",
        "query": {
          "term": {
            "_id": "gang1"
        }
      }
    }
  }
}

```

The first query return an error : "[parent\_id] \_parent field has no parent type configured" and the second one return the expected document.

Here is my test setup on pastebin: [http://pastebin.com/vPW6ieUV](http://pastebin.com/vPW6ieUV)

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [December 27, 2016, 2:51pm UTC](https://discuss.elastic.co/t/parent-id-query-problem/70073/2 "2016-12-27T14:51:08Z")

</div>

Hi,

Your "gangs" indice holds 3 types of documents: gang, territory & entity. When you run your query on /gangs, it apply the query on all types, so it return an error for "gang" type because it doesn't have a \_parent field.  
Try to run your query on only one or two types having a \_parent field:

```
GET /gangs/territory/_search
{
  "query": {
"parent_id" : {
  "type" : "gang",
  "id" : "gang1"
}
  }
}
```

---

<div class="post-metadata">

**Author:** ![theredcat](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theredcat/32/14164_2.png) [@theredcat](https://discuss.elastic.co/u/theredcat)\
**Post date:** [December 27, 2016, 2:58pm UTC](https://discuss.elastic.co/t/parent-id-query-problem/70073/3 "2016-12-27T14:58:29Z")

</div>

Actually, i've found my mistake. I misread the documentation:

> [@Documentation](#):
>
> Type: The child type. This must be a type with \_parent field.

I was doing a query whith the parent type in the "type" field of the "parent\_id" query, where you should use the child type.

---

<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 24, 2017, 2:58pm UTC](https://discuss.elastic.co/t/parent-id-query-problem/70073/4 "2017-01-24T14:58:49Z")

</div>

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