# Elasticsearch output plugin .. with script not working

**URL:** <https://discuss.elastic.co/t/elasticsearch-output-plugin-with-script-not-working/184431>\
**Category:** Logstash\
**Created:** [June 5, 2019, 5:41pm UTC](https://discuss.elastic.co/t/elasticsearch-output-plugin-with-script-not-working/184431 "2019-06-05T17:41:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hive](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hive/32/46651_2.png) [@hive](https://discuss.elastic.co/u/hive)\
**Post date:** [June 5, 2019, 5:41pm UTC](https://discuss.elastic.co/t/elasticsearch-output-plugin-with-script-not-working/184431/1 "2019-06-05T17:41:02Z")

</div>

**Below UPADTE using script works fine using REST client**

[http://localhost:9200/my/associate/54630935\_105471/\_update?pretty](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](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
}

```

}

---

<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:** [July 3, 2019, 5:41pm UTC](https://discuss.elastic.co/t/elasticsearch-output-plugin-with-script-not-working/184431/2 "2019-07-03T17:41:02Z")

</div>

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