How to throw a error in painless

I want to return something so that I can identify that the below update is exceuted from "if " section or the "else" section. Is there a way to return or throw an exception

POST customer/_update_by_query
{
"script":{
"source":"""
if(some condition)
{
// some processing
}
else
// throw some exception or return something so that it can be identified
"""
},
"query":{
// some Query here
}

}

Thank You For your Help

1 Like

Hey,

I am not sure I fully get the requirement, do you want to update the document in both cases or only in one. If the latter you can set ctx.op = "noop" which means, the document will not get updated. If the former, than it might make sense to add a second field which describes which action had been taken.

Hope this helps!

--Alex

Hey Alex,

It is the latter one i.e. I want to update in only one case.
Your answer is helpful but what if I want to return some personalized message
through the response of the query if it go to the "else" case.
Will I be able to do that.

1 Like

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