Pipeline processor script error


(Vesna Velichkovich) #1

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?


(Jake Landis) #2

As you note the triple quotes are not valid JSON. There is an issue for this: 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

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


(Vesna Velichkovich) #3

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


(system) #4

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