# Pipeline processor script error

**URL:** <https://discuss.elastic.co/t/pipeline-processor-script-error/149508>\
**Category:** Elasticsearch\
**Created:** [September 21, 2018, 6:56pm UTC](https://discuss.elastic.co/t/pipeline-processor-script-error/149508 "2018-09-21T18:56:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vvelichkovich](https://avatars.discourse-cdn.com/v4/letter/v/edb3f5/32.png) [@vvelichkovich](https://discuss.elastic.co/u/vvelichkovich)\
**Post date:** [September 21, 2018, 6:56pm UTC](https://discuss.elastic.co/t/pipeline-processor-script-error/149508/1 "2018-09-21T18:56:30Z")

</div>

I have pipeline script that seams it works fine when I script it from Kibana, and it looks like this:

PUT \_ingest/pipeline/vv\_test  
{  
"description": "changing NaN",  
"processors": [  
{  
"script": {  
"source": """  
if(ctx.snapshots != null ) {  
for (int i=0; i \< ctx.snapshots.size(); i++) {  
List toRemove = new ArrayList();  
Set keySet = ctx.snapshots[i].keySet();  
for (key in keySet) {  
if(ctx.snapshots[i].get(key) == 'NaN') {  
toRemove.add(key)  
}  
}  
for (int j=0; j \< toRemove.size(); j++) {  
ctx.snapshots[i].remove(toRemove[j]);  
}  
}  
}  
""",  
"lang": "painless"  
}}  
]  
}

If I try to use curl command to add this pipeline (or same issue is when I try to create pipeline from service using HttpURLConnection since there is no API in 6.2.4 ), I have issue with invalid JSON, which is obvious why (those 3 quotes at start and end of script source).  
I just can't make it work, when I make it valid JSON by escaping quotes inside script, then I get 500 error, compile error, complaining on ".

Does anyone know what I am doing wrong? I feel if I have it solved for

curl -XPUT 'localhost:9200/\_ingest/pipeline/vv\_test' -H 'Content-Type: application/json' -d'  
{...  
}'

then I would know what should my string look like for HttpURLConnection . Or maybe not?

---

<div class="post-metadata">

**Author:** ![jakelandis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jakelandis/32/36163_2.png) [@jakelandis](https://discuss.elastic.co/u/jakelandis)\
**Post date:** [September 24, 2018, 2:19pm UTC](https://discuss.elastic.co/t/pipeline-processor-script-error/149508/2 "2018-09-24T14:19:52Z")

</div>

As you note the triple quotes are not valid JSON. There is an issue for this: [https://github.com/elastic/kibana/issues/15628](https://github.com/elastic/kibana/issues/15628).

For inline scripts (like your example), you can simply remove all the new lines and make the script live on one long line any double quotes `"` will need to be escaped, but single quotes (like you have) do not.

Kibana has a copy as cURL which should get you closer, but you may need to still do a little bit of scrubbing (like removing the \n characters).  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/f/5f0aa4893edfab1f7ea3ce544730c69c0762a6ae.png)

If the issue is with the calling from Java, I would need to see the Java code in question.

---

<div class="post-metadata">

**Author:** ![vvelichkovich](https://avatars.discourse-cdn.com/v4/letter/v/edb3f5/32.png) [@vvelichkovich](https://discuss.elastic.co/u/vvelichkovich)\
**Post date:** [September 24, 2018, 4:33pm UTC](https://discuss.elastic.co/t/pipeline-processor-script-error/149508/3 "2018-09-24T16:33:14Z")

</div>

That is fantastic! It worked! I didn't see before Kibana - copy as cURL.

---

<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:** [October 22, 2018, 4:33pm UTC](https://discuss.elastic.co/t/pipeline-processor-script-error/149508/4 "2018-10-22T16:33:32Z")

</div>

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