# Insert records for parent/child in same index of elastic search

**URL:** <https://discuss.elastic.co/t/insert-records-for-parent-child-in-same-index-of-elastic-search/285385>\
**Category:** Logstash\
**Created:** [September 28, 2021, 3:40pm UTC](https://discuss.elastic.co/t/insert-records-for-parent-child-in-same-index-of-elastic-search/285385 "2021-09-28T15:40:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![manjurgani](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@manjurgani](https://discuss.elastic.co/u/manjurgani)\
**Post date:** [September 28, 2021, 3:40pm UTC](https://discuss.elastic.co/t/insert-records-for-parent-child-in-same-index-of-elastic-search/285385/1 "2021-09-28T15:40:28Z")

</div>

I have created a mapping in Elasticsearch like below

```auto
POST /INDEX
{
   "mappings": {
       "properties": {
           "id": {
               "type": "keyword"
           },
           "join_field": {
               "type": "join",
               "relations": {
                   "coverage": "readership"
               }
           }
       }
   }
}

```

In above mapping "coverage" is parent and "readership" is child.

(2) I am inserting a document into parent (coverage) using below API call .

```auto
POST /INDEX
{
    "id": 102,
    "accountId": 102,
    "users": [{
            "id": 199191,
            "name": "user1"
        }, {
            "id": 199192,
            "name": "user2"
        }
    ],
    "join_field": "coverage"
}

```

(3) I am inserting child record as follows.

```auto
PUT INDEX/_doc/102-5001?routing=102&refresh{
    'id': 5001,
    'accountId': 102,
    "contactId": 5000,
    "reportId": 2,
    "click": 10,
    "view": 2,
    "date": "12-10-1995",
    "join_field": {
        "name": "readership",
        "parent": 102
    }
}

```

Question. How can i achieve this using logstash input and output plugins.

---

<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:** [October 26, 2021, 3:41pm UTC](https://discuss.elastic.co/t/insert-records-for-parent-child-in-same-index-of-elastic-search/285385/2 "2021-10-26T15:41:14Z")

</div>

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