# How to throw a error in painless

**URL:** https://discuss.elastic.co/t/how-to-throw-a-error-in-painless/176337
**Category:** Elasticsearch
**Created:** [April 11, 2019, 7:15am UTC](https://discuss.elastic.co/t/how-to-throw-a-error-in-painless/176337 "2019-04-11T07:15:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Anurag\_Mankar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anurag_mankar/32/42607_2.png) [@Anurag\_Mankar](https://discuss.elastic.co/u/Anurag_Mankar)
#### Post date: [April 11, 2019, 7:15am UTC](https://discuss.elastic.co/t/how-to-throw-a-error-in-painless/176337/1 "2019-04-11T07:15:45Z")

</div>

> 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

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [April 11, 2019, 2:07pm UTC](https://discuss.elastic.co/t/how-to-throw-a-error-in-painless/176337/2 "2019-04-11T14:07:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Anurag\_Mankar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anurag_mankar/32/42607_2.png) [@Anurag\_Mankar](https://discuss.elastic.co/u/Anurag_Mankar)
#### Post date: [April 11, 2019, 3:12pm UTC](https://discuss.elastic.co/t/how-to-throw-a-error-in-painless/176337/3 "2019-04-11T15:12:01Z")

</div>

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.

---

<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: [May 9, 2019, 3:12pm UTC](https://discuss.elastic.co/t/how-to-throw-a-error-in-painless/176337/4 "2019-05-09T15:12:03Z")

</div>

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