Elasticsearch output plugin .. with script not working

Below UPADTE using script works fine using REST client

http://localhost:9200/my/associate/54630935_105471/_update?pretty

{
"upsert": {
"positions": [

]

},
"script": {
"params": {
"pos": {
"eff_date_end": "4000-12-31T05:00:00.000Z",
"pfid": "54630935_109517-second",
"eff_date": "1970-01-01T05:00:00.000Z",
"employee_oid": "54630935_109515",
"f_full_time": 1
}
},
"inline": "if (ctx._source.positions.indexOf(params.pos) > -1){ ctx._source.positions.remove(ctx._source.positions.indexOf(params.pos)); ctx._source.positions.add(params.pos);} else ctx._source.positions.add(params.pos)",
"lang": "painless"
},
"scripted_upsert": true
}

I am trying to achieve the same using logstash elasticsearch output (code below) ... that does not work ... looks like the whole of SCRIPT is ignored and actual event is sent to ES
I am new to logstash and ES ... any help is really appreciated.

input {
jdbc {
jdbc_driver_library => "/docs/jars/ojdbc8-12.2.0.1.jar"
jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver"
jdbc_connection_string => "jdbc:oracle:thin:@51.16.71.160:1521/wfc32d_svc1"
jdbc_user => "XXXXX"
jdbc_password => "YYYYY"
statement => "SELECT employee_oid, pfid, eff_date, eff_date_end, f_full_time FROM wfn10sch00032.chr_emp_position WHERE vpd_key = 'WNVPD0011530304' AND employee_oid IN ('54630935_105471')"
}
}

output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "my"
document_type => "associate"
document_id => "%{employee_oid}"
#doc_as_upsert => true
upsert => '{"positions": }'
action => "update"
scripted_upsert => "true"
script_lang => "painless"
script_type => "inline"
script => '
def pos = {
"employee_oid": event.get("employee_oid"),
"pfid": event.get("pfid"),
"eff_date": event.get("eff_date"),
"eff_date_end": event.get("eff_date_end"),
"f_full_time": event.get("f_full_time")
};
if (ctx._source.positions.indexOf(pos) > -1){
ctx._source.positions.remove(ctx._source.positions.indexOf(pos));
ctx._source.positions.add(pos);
} else {
ctx._source.positions.add(pos);
}
'

}

stdout{
	codec => json
}

}

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