Multi-statement scripts in elasticsearch

Hi all,
I have indexed a document
PUT test/_doc/1
{
"counter" : 1,
"tags" : ["red"]
}
I am using script to update my content of the documents
POST test/_doc/1/_update
{
"script" : {
"source": "ctx._source.tags.add(params.tag)",
"lang": "painless",
"params" : {
"tag" : "blue"
}
}
}
POST test/_doc/1/_update
{
"script" : "ctx._source.new_field = 'value_of_new_field'"
}
This two scripts are working fine individually, I want to use these two script statements in a single "_update" API. Is it possible to do this?

You can write multiple statements in painless scripts by separating the lines with semicolon (;).

1 Like

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