# How to migrate parent child relation data from RDBMS, through logstash to Elastic?

**URL:** <https://discuss.elastic.co/t/how-to-migrate-parent-child-relation-data-from-rdbms-through-logstash-to-elastic/169819>\
**Category:** Logstash\
**Created:** [February 25, 2019, 11:48am UTC](https://discuss.elastic.co/t/how-to-migrate-parent-child-relation-data-from-rdbms-through-logstash-to-elastic/169819 "2019-02-25T11:48:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasad1986](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@prasad1986](https://discuss.elastic.co/u/prasad1986)\
**Post date:** [February 25, 2019, 11:48am UTC](https://discuss.elastic.co/t/how-to-migrate-parent-child-relation-data-from-rdbms-through-logstash-to-elastic/169819/1 "2019-02-25T11:48:56Z")

</div>

I created Parent and child relation through Kibana tool.  
Index :demosampleindex  
documenttype: itemdoctype  
Parent Relation:itemjoin  
child Relation :itemjoin

Syntax:  
PUT demosampleindex  
{  
"settings": {  
"number\_of\_shards": 1,  
"number\_of\_replicas": 1  
},  
"mappings": {  
"itemdoctype": {  
"properties": {  
"itemjoinfield": {  
"type": "join",  
"relations": {  
"itemjoin": "cfjoin"  
}  
}  
}  
}  
}  
}

After creation of index try to move data from logstash. Parent reation data able migrate it, but child relation data not able to achive it.  
"item\_id" is document\_id of parent object.

Logstash Syntax:  
input {  
jdbc {

```
    jdbc_connection_string => "jdbc:oracle:thin:@192.168.142.157:1521:nios157"
    	
    jdbc_user => "C2_DEV_NIOS5_OLTP2"
  		
	jdbc_password => "nios"
	 
    jdbc_driver_library => "D:/SVN/PRODUCT/NIOS/Engg/Dev/6.0/lib/ojdbc6.jar"
    					
    jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver"
    				
	statement_filepath => "select distinct item.item_id as itemid, item.item_id||'_cfobj' as itemidstr,'cfjoin' as cfjoinname, item.customfieldname as customfieldname, item.customfieldvalue as customfieldvalue from item_table item "

}

```

}  
filter {

```
mutate {
    add_field => { "_parent" => "%{itemid}" }
}

 aggregate {
   task_id => "%{itemid}"
   code => "
    map['itemidstr'] ||= event.get('itemidstr')

	map['itemjoinfield'] = {
		'name' => event.get('cfjoinname')
	}						
						
	map['cf_list'] ||= []
	map['customfields'] ||= []
	if (event.get('customfieldname') != nil)
		if !( map['cf_list'].include? event.get('customfieldname') ) 
		 map['cf_list'] << event.get('customfieldname')
			  map['customfields'] << {
				'customfieldname' => event.get('customfieldname'),
				'customfieldvalue' => event.get('customfieldvalue')
			}
		end	
	end
	
	"

   push_previous_map_as_event => true
   timeout => 150000
 }
mutate { 
	remove_field => ["cf_list"]
}

```

}  
output {  
elasticsearch {  
index =\> "demosampleindex"  
document\_type =\> "itemdoctype"  
document\_id =\> "%{itemidstr}"  
hosts =\> ["localhost:9200"]  
routing =\> "%{itemid}"  
parent =\> "%{itemid}"  
}  
}

Exception log:

[2019-02-25T16:21:08,163][WARN][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=\>400, :action=\>["index", {:\_id=\>"576044\_cfobj", :\_index=\>"demosampleindex", :\_type=\>"itemdoctype", :routing=\>"576044", :parent=\>"576044"}, #LogStash::Event:0x48d2b7f4], :response=\>{"index"=\>{"\_index"=\>"demosampleindex", "\_type"=\>"itemdoctype", "\_id"=\>"576044\_cfobj", "status"=\>400, "error"=\>{"type"=\>"illegal\_argument\_exception", "reason"=\>"can't specify parent if no parent field has been configured"}}}}  
[2019-02-25T16:21:08,214][WARN][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=\>400, :action=\>["index", {:\_id=\>"576044\_cfobj", :\_index=\>"demosampleindex", :\_type=\>"itemdoctype", :routing=\>"576044", :parent=\>"576044"}, #LogStash::Event:0x30a471ba], :response=\>{"index"=\>{"\_index"=\>"demosampleindex", "\_type"=\>"itemdoctype", "\_id"=\>"576044\_cfobj", "status"=\>400, "error"=\>{"type"=\>"illegal\_argument\_exception", "reason"=\>"can't specify parent if no parent field has been configured"}}}}  
[2019-02-25T16:21:08,216][WARN][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=\>400, :action=\>["index", {:\_id=\>"576044\_cfobj", :\_index=\>"demosampleindex", :\_type=\>"itemdoctype", :routing=\>"576044", :parent=\>"576044"}, #LogStash::Event:0x35eeb606], :response=\>{"index"=\>{"\_index"=\>"demosampleindex", "\_type"=\>"itemdoctype", "\_id"=\>"576044\_cfobj", "status"=\>400, "error"=\>{"type"=\>"illegal\_argument\_exception", "reason"=\>"can't specify parent if no parent field has been configured"}}}}  
[2019-02-25T16:21:08,294][WARN][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=\>400, :action=\>["index", {:\_id=\>"576044\_cfobj", :\_index=\>"demosampleindex", :\_type=\>"itemdoctype", :routing=\>"%{itemid}", :parent=\>"%{itemid}"}, #LogStash::Event:0x5f3f7658], :response=\>{"index"=\>{"\_index"=\>"demosampleindex", "\_type"=\>"itemdoctype", "\_id"=\>"576044\_cfobj", "status"=\>400, "error"=\>{"type"=\>"illegal\_argument\_exception", "reason"=\>"can't specify parent if no parent field has been configured"}}}}  
[2019-02-25T16:21:08,298][WARN][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=\>400, :action=\>["index", {:\_id=\>"576044\_cfobj", :\_index=\>"demosampleindex", :\_type=\>"itemdoctype", :routing=\>"576044", :parent=\>"576044"}, #LogStash::Event:0x2ea1e71f], :response=\>{"index"=\>{"\_index"=\>"demosampleindex", "\_type"=\>"itemdoctype", "\_id"=\>"576044\_cfobj", "status"=\>400, "error"=\>{"type"=\>"illegal\_argument\_exception", "reason"=\>"can't specify parent if no parent field has been configured"}}}}  
[2019-02-25T16:21:08,300][WARN][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=\>400, :action=\>["index", {:\_id=\>"576044\_cfobj", :\_index=\>"demosampleindex", :\_type=\>"itemdoctype", :routing=\>"576044", :parent=\>"576044"}, #LogStash::Event:0x3875c020], :response=\>{"index"=\>{"\_index"=\>"demosampleindex", "\_type"=\>"itemdoctype", "\_id"=\>"576044\_cfobj", "status"=\>400, "error"=\>{"type"=\>"illegal\_argument\_exception", "reason"=\>"can't specify parent if no parent field has been configured"}}}}  
[2019-02-25T16:21:08,726][INFO][logstash.pipeline] Pipeline has terminated {:pipeline\_id=\>"main", :thread=\>"#\<Thread:0x4562c90c run\>"}

---

<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:** [March 25, 2019, 11:48am UTC](https://discuss.elastic.co/t/how-to-migrate-parent-child-relation-data-from-rdbms-through-logstash-to-elastic/169819/2 "2019-03-25T11:48:57Z")

</div>

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