# Painless script failing whenever you fetch a field from doc

**URL:** <https://discuss.elastic.co/t/painless-script-failing-whenever-you-fetch-a-field-from-doc/145578>\
**Category:** Kibana\
**Created:** [August 22, 2018, 3:15pm UTC](https://discuss.elastic.co/t/painless-script-failing-whenever-you-fetch-a-field-from-doc/145578 "2018-08-22T15:15:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![obaid](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/obaid/32/34653_2.png) [@obaid](https://discuss.elastic.co/u/obaid)\
**Post date:** [August 22, 2018, 3:15pm UTC](https://discuss.elastic.co/t/painless-script-failing-whenever-you-fetch-a-field-from-doc/145578/1 "2018-08-22T15:15:38Z")

</div>

Hi,  
I am trying out ‘Painless’ scripts on Kibana (by creating scripted fields [Index patterns has been renamed to data views. | Kibana Guide [8.11] | Elastic](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html)). My script runs just fine until I access a field from “doc” object. I immediately get following Warning on Kibana UI:

> Warning
> 
> Courier Fetch: 1 of 2 shards failed.

For some reason, line 6 of my script cause the warning and no logs are displayed on UI. If I remove this line(along with braces), it works just fine:

> String featureName="pendingApp";  
> String key="customerFeatures.0.featureId";
> 
> if(doc.containsKey(key))  
> {  
> if(doc[key]=='yes')  
> {  
> return "AA";  
> }  
> }  
> return "N/A";

On Kibana, following is how actually the logs appear (you can see the field 'customerFeatures.0.featureId' is available):

 ![41%20AM](https://us1.discourse-cdn.com/elastic/original/3X/6/3/63ff96271691ee7f6f875415fe62af566adc47bb.png)

Do I need to enable something on Kibana, or change the indexing somehow?

I will really appreciate any help,

Thanks

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [August 24, 2018, 10:50am UTC](https://discuss.elastic.co/t/painless-script-failing-whenever-you-fetch-a-field-from-doc/145578/2 "2018-08-24T10:50:27Z")

</div>

Hello,

What are you trying to accomplish with the scripted field?  
If you are looking for the `customerFeatures.0.featureId` field to have the value `yes` you need to use `doc[key].value == "yes"`

---

<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:** [September 21, 2018, 10:50am UTC](https://discuss.elastic.co/t/painless-script-failing-whenever-you-fetch-a-field-from-doc/145578/3 "2018-09-21T10:50:41Z")

</div>

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