# Parentchild relationship in logstash

**URL:** https://discuss.elastic.co/t/parentchild-relationship-in-logstash/100207
**Category:** Logstash
**Created:** [September 12, 2017, 12:22pm UTC](https://discuss.elastic.co/t/parentchild-relationship-in-logstash/100207 "2017-09-12T12:22:01Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![swaplogstash](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@swaplogstash](https://discuss.elastic.co/u/swaplogstash)
#### Post date: [September 12, 2017, 12:22pm UTC](https://discuss.elastic.co/t/parentchild-relationship-in-logstash/100207/1 "2017-09-12T12:22:01Z")

</div>

I am using Multiple Jdbc input plugins(since I have two Sqls , one is parent and other is child table) to load data into elastic which has parent child relationship between two mappings. Can you please provide me sample code how to load parent document id into child document. I used parent config option of Elastic output plugin but didnot work.

---

<div class="post-metadata">

### Author: ![malhotras](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@malhotras](https://discuss.elastic.co/u/malhotras)
#### Post date: [September 19, 2017, 9:15am UTC](https://discuss.elastic.co/t/parentchild-relationship-in-logstash/100207/2 "2017-09-19T09:15:08Z")

</div>

It is quite simple, but depends on your configuration a lot. So if you use aggregate filter plugin and define a parent child relation...like:

```
 filter {
 aggregate {
  task_id => "%{some_id}"
  code => "
map['parent] ||= {}
map['parent_id'] = event.get('parent_id')
map['parent_name'] = event.get('parent_name')
     map['parent']['child'] ||= []
     map['parent']['child'] << {'child_id' => event.get('child_id'),'child_name' => event.get('child_name'),'parent_id' => event.get('parent_id')}
     event.cancel()

"
 push_previous_map_as_event => true
 timeout => 5
}
}
```

---

<div class="post-metadata">

### Author: ![swaplogstash](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@swaplogstash](https://discuss.elastic.co/u/swaplogstash)
#### Post date: [September 19, 2017, 1:03pm UTC](https://discuss.elastic.co/t/parentchild-relationship-in-logstash/100207/3 "2017-09-19T13:03:10Z")

</div>

Thank you. It worked.

---

<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 17, 2017, 1:03pm UTC](https://discuss.elastic.co/t/parentchild-relationship-in-logstash/100207/4 "2017-10-17T13:03:33Z")

</div>

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