# Index parent-child with \_id

**URL:** <https://discuss.elastic.co/t/index-parent-child-with-id/215491>\
**Category:** Elasticsearch\
**Created:** [January 17, 2020, 4:00pm UTC](https://discuss.elastic.co/t/index-parent-child-with-id/215491 "2020-01-17T16:00:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnkary](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@johnkary](https://discuss.elastic.co/u/johnkary)\
**Post date:** [January 17, 2020, 4:00pm UTC](https://discuss.elastic.co/t/index-parent-child-with-id/215491/1 "2020-01-17T16:00:46Z")

</div>

Hi all! I use parent-child model in my index "npk" and here are some questions basically on the ways i can search. I studied [has-child](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html) and [has-parent](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html) queries but i don't get any results for the docs i inserted to this index.

My index creation:

```
PUT /npk
{ 
    "settings" : {
        "index" : {
            "number_of_shards" : 3, 
            "number_of_replicas" : 2 
        }
    },
  "dynamic": true,
  "mappings": {
    "doc": {
      "properties": {
        "my_join_field" : {
                "type" : "join",
                "relations": {
                    "header": "body"
                }}}}}}

```

I indexed 2 parents with \_ids 1 and 4:

```
PUT /npk/doc/1
{
        "header_column_1": "value1",
        "header_column_2": "value2",
        "my_join_field": "header"
}

```

I indexed 2 children for each parent with ids 2, 3 and 5, 6:

```
PUT /npk/doc/2?routing=1&refresh
{ 
  "body_column_1": 220,
  "body_column_2": 220,
  "my_join_field": {
    "name": "body",
    "parent": "1"
  }
}  

```

My question is: Both parent and child have to be in the field ' **\_id**' ? Do i implement it in the right way here? I have read somewhere that ' **\_id**' field has a limit of 512 bytes, so we cannot increase it too much. I have made a script that puts parents-children and in the ' **\_id**' i have an auto-increment routine to increase it as a number. Is it right to be a number? Because by default it takes alphanumeric values.

The weird here is that when i run the below query for both parents (\_ids 1 and 4) to get their children i receive correct results:

```
GET /npk/_search
{
  "query": {
      "parent_id": {
          "type": "body",
          "id": "4"
      }
  }

```

}

response:

```
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 0.87546873,
    "hits": [
      {
        "_index": "npk",
        "_type": "doc",
        "_id": "5",
        "_score": 0.87546873,
        "_routing": "1",
        "_source": {
          "body_column_1": 200,
          "body_column_2": 200,
          "my_join_field": {
            "name": "body",
            "parent": "4"
          }
        }
      },
      {
        "_index": "npk",
        "_type": "doc",
        "_id": "6",
        "_score": 0.87546873,
        "_routing": "1",
        "_source": {
          "body_column_1": 220,
          "body_column_2": 220,
          "my_join_field": {
            "name": "body",
            "parent": "4"
          }
        }
      }
    ]
  }
}

```

... BUT, when i run the has\_child query

```
GET /npk/_search
{
    "query": {
        "has_child" : {
            "type" : "body",
            "query" : {
                "match_all" : {}
            },
            "max_children": 10,
            "min_children": 1,
            "score_mode" : "min"
        }
    }
}

```

i get results only for the parent with \_id = 1. The other with \_id=4 is missing!

```
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "npk",
        "_type": "doc",
        "_id": "1",
        "_score": 1,
        "_source": {
          "header_column_1": "value1",
          "header_column_2": "value1",
          "my_join_field": "header"
        }
      }
    ]
  }
}
```

---

<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:** [February 14, 2020, 4:08pm UTC](https://discuss.elastic.co/t/index-parent-child-with-id/215491/2 "2020-02-14T16:08:15Z")

</div>

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