# How to use jdbc to import data into nested objects?

**URL:** https://discuss.elastic.co/t/how-to-use-jdbc-to-import-data-into-nested-objects/52871
**Category:** Logstash
**Created:** [June 15, 2016, 1:53pm UTC](https://discuss.elastic.co/t/how-to-use-jdbc-to-import-data-into-nested-objects/52871 "2016-06-15T13:53:11Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![iti](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@iti](https://discuss.elastic.co/u/iti)
#### Post date: [June 23, 2017, 4:48am UTC](https://discuss.elastic.co/t/how-to-use-jdbc-to-import-data-into-nested-objects/52871/5 "2017-06-23T04:48:33Z")

</div>

assuming you have a mapping like:  
"mappings": {  
"atype": {  
"properties": {  
"@timestamp": {  
"type": "date"  
},  
"@version": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"id": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"nestedpath": {  
"type": "nested",  
"properties": {  
"nested\_field": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
}  
}  
},  
"tags": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
}  
}  
}  
}  
one nested field with parent doc (id and tag + timestamp and version ES fields)

Note: order by is important since aggregate filter requires that.

```
jdbc {

```

...  
statement =\> "select id,tag, child.nested\_field from parent left outer join child on [parent.id=child.id](http://parent.id=child.id) order by id"  
type =\> "atype"  
....  
}  
filter:{  
#use @metadata field to prevent saving the field  
mutate {  
add\_field =\> { "[@metadata][type]" =\> "%{type}" }  
remove\_field =\> ["type"]  
}  
if "atype" == [@metadata][type] {  
aggregate {  
task\_id =\> "%{id}"  
code =\> "  
map['id'] ||= event.get('id')  
map['@metadata'] = event.get('@metadata')  
map['nested\_path'] ||= []  
map['nested\_path'] \< \< {'nested\_field' =\> event.get('nested\_field')}  
"  
push\_previous\_map\_as\_event =\> true  
timeout =\>5  
timeout\_tags =\> ['aggregated']  
}  
}  
}  
output {  
//only ingest to ES when aggregated. timeout\_tags put it there  
if "aggregated" in [tags]{  
elasticsearch {  
index =\> "aindex"  
document\_type =\> "%{[@metadata][type]}"   
document\_id =\> "%{id}"  
hosts =\> ......  
action =\> "update"  
doc\_as\_upsert =\> true  
}  
}  
}

---

_[View the full topic](https://discuss.elastic.co/t/how-to-use-jdbc-to-import-data-into-nested-objects/52871)._
