I am using parent-child relation between 2 entities. They are fetched from the database where they come from 2 different tables. I use the SQL join statement for them in logstash config file. Details of the config file:
input {
jdbc {
jdbc_connection_string => "url"
jdbc_user => "user"
jdbc_password => "pswd"
jdbc_driver_library => "./ifxjdbc-3-50-JC7.jar"
jdbc_driver_class => "com.informix.jdbc.IfxDriver"
statement => ["SELECT st1.name as s_name, st1.pnumber, st1.mnumber, st2.name as comp_name, zen.s_id, zen.comp_id, zen.conc_1, zen.conc_2 FROM sub_zen zen join sub st1 on st1.id = zen.s_id join sub st2 on st2.id = zen.comp_id"]}}
filter {mutate {remove_field =>["@timestamp"]}}
output {
stdout { codec => json_lines }
elasticsearch {
"manage_template" => "false"
"hosts" => "url"
"index" => "test-migrate"
"parent" => "%{s_id}"}}
So, what I am doing is I am joining 2 tables first on "id" which is primary key in Table sub (st1 & st2) with table sub_zen first on "s_id" and then "comp_id". So, id from sub can be either s_id or comp_id in sub_zen.
I define the mapping in ES to have dynamic strict mapping and set manage_template false in logstash. Now, I would like to index the data into ES where I will have 2 different types.
Sub with fields: s_id,s_name,mnumber and pnumber
Comp with fields: comp_id, comp_name, conc_1,conc_2
I have defined my mapping in ES already:
curl -GET url:9200/test-migrate/_mapping?pretty
{
"test-migrate" : {
"mappings" : {
"sub" : {
"dynamic" : "strict",
"properties" : {
"mnumber" : {
"type" : "long"
},
"pnumber" : {
"type" : "long"
},
"s_id" : {
"type" : "long"
},
"s_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"comp" : {
"dynamic" : "strict",
"_parent" : {
"type" : "sub"
},
"_routing" : {
"required" : true
},
"properties" : {
"comp_id" : {
"type" : "long"
},
"comp_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"conc_1" : {
"type" : "float"
},
"conc_2" : {
"type" : "float"
}
}
}
}
}
}
The current logstash config file does not index the data correctly as i would like, what shall i change? Any pointers? How can i guide logstash to index fields (id,name,pnumber,mnumber) to sub and (id,name,conc_1,conc_2) to comp and also respect parent child relation. Here sub is a parent which can have many comp child. Any pointers?