# Painless script error

**URL:** https://discuss.elastic.co/t/painless-script-error/306243
**Category:** Kibana
**Tags:** painless
**Created:** [June 2, 2022, 2:43pm UTC](https://discuss.elastic.co/t/painless-script-error/306243 "2022-06-02T14:43:11Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Surya\_Raviraj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/surya_raviraj/32/77606_2.png) [@Surya\_Raviraj](https://discuss.elastic.co/u/Surya_Raviraj)
#### Post date: [June 2, 2022, 2:43pm UTC](https://discuss.elastic.co/t/painless-script-error/306243/1 "2022-06-02T14:43:11Z")

</div>

Hi, I have a script below -  
if(doc['not\_shipped\_shortfall'].value \< 0) { return doc['not\_shipped\_shortfall'].value; }else{ return 0; }

when I click 'preview results' I see my desired result and looks like the script is working fine. However, when I try to use this metric in the visualizer I get the following error -

```auto
org.elasticsearch.index.fielddata.ScriptDocValues$Doubles.get(ScriptDocValues.java:249)
org.elasticsearch.index.fielddata.ScriptDocValues$Doubles.getValue(ScriptDocValues.java:243)
if(doc['not_shipped_shortfall'].value < 0.0) { 
                               ^---- HERE

```

I'd greatly appreciate if you can point me in the right direction.

---

<div class="post-metadata">

### Author: ![marone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marone/32/87145_2.png) [@marone](https://discuss.elastic.co/u/marone)
#### Post date: [June 2, 2022, 4:11pm UTC](https://discuss.elastic.co/t/painless-script-error/306243/2 "2022-06-02T16:11:04Z")

</div>

> [@Surya\_Raviraj](#):
>
> if(doc['not\_shipped\_shortfall'].value \< 0) { return doc['not\_shipped\_shortfall'].value; }else{ return 0; }

Hey @Surya_Raviraj ,  
First, I created a `test` index with only one field to test:

```auto
PUT test
{
  "mappings": {
    "properties": {
      "float_field": {
        "type": "float"
      }
    }
  }
}

POST test/_doc/1
{
  "float_field": 1.2
}
POST test/_doc/2
{
  "float_field": -1.2
}

```

Then copied/pasted your code as it is and worked in the scripted field in the index pattern:

```auto
if(doc['float_field'].value < 0) { 
    return doc['float_field'].value; 
}
else {
    return 0; 
}

```

the script above worked for me in the previou results tab

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/c/8c5859aaa3dd433e33d44ca55c4a8d0a7b7971bd.png)

Can you please tell us additional information: what elastic version are you using? and also paste the whole stack trace, there is a reason field at the bottom of the error.  
and I can use the `new_field` created in a vizualisation:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/4/9408c57b738fb16b6695e8273991671465cac5c1.png)

**FYI I tested that on elastic 8.0.1.**

---

<div class="post-metadata">

### Author: ![Surya\_Raviraj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/surya_raviraj/32/77606_2.png) [@Surya\_Raviraj](https://discuss.elastic.co/u/Surya_Raviraj)
#### Post date: [June 2, 2022, 4:28pm UTC](https://discuss.elastic.co/t/painless-script-error/306243/3 "2022-06-02T16:28:24Z")

</div>

Thanks Marone, I am currently using elastic version 7.10.  
How can I find the whole stack trace? The error message I pasted was copied when I try to use it in a visualization.

---

<div class="post-metadata">

### Author: ![Surya\_Raviraj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/surya_raviraj/32/77606_2.png) [@Surya\_Raviraj](https://discuss.elastic.co/u/Surya_Raviraj)
#### Post date: [June 2, 2022, 6:34pm UTC](https://discuss.elastic.co/t/painless-script-error/306243/4 "2022-06-02T18:34:58Z")

</div>

Something to also note that is that the field I am working with has a mapping type of double. Fortunately, all the numbers in that field are/can only whole numbers. Not sure if that changes anything.

---

<div class="post-metadata">

### Author: ![marone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marone/32/87145_2.png) [@marone](https://discuss.elastic.co/u/marone)
#### Post date: [June 3, 2022, 12:55pm UTC](https://discuss.elastic.co/t/painless-script-error/306243/5 "2022-06-03T12:55:23Z")

</div>

I updated the mapping to double and still working.

For the whole stacktrace I thought it was printed from Elasticsearch side, but since you got it when trying to make the vizualisation, the code is executed on the kibana side.

Do you have the new field processed on Discover tab? Like this:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/9/2903cbede5193d4510eb46876cd0551c768c0591.png)

---

<div class="post-metadata">

### Author: ![Surya\_Raviraj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/surya_raviraj/32/77606_2.png) [@Surya\_Raviraj](https://discuss.elastic.co/u/Surya_Raviraj)
#### Post date: [June 6, 2022, 3:29pm UTC](https://discuss.elastic.co/t/painless-script-error/306243/6 "2022-06-06T15:29:58Z")

</div>

Yes, I am able to see the values on the discover tab. I am not able to use this field on my visualization though. That's what is confusing me. Any hints or tips that you might have?

 ![Screen Shot 2022-06-06 at 10.28.49 AM](https://us1.discourse-cdn.com/elastic/original/3X/4/3/43fe48d2bcdbe61ac84ebe73d63e4b5e4d53d9c2.png)

---

<div class="post-metadata">

### Author: ![marone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marone/32/87145_2.png) [@marone](https://discuss.elastic.co/u/marone)
#### Post date: [June 7, 2022, 9:00am UTC](https://discuss.elastic.co/t/painless-script-error/306243/7 "2022-06-07T09:00:32Z")

</div>

That's confusing me as well, maybe if you can update your elastic to a newer version? or try to create an issue on [Issues · elastic/kibana · GitHub](https://github.com/elastic/kibana/issues)

---

<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: [July 5, 2022, 9:01am UTC](https://discuss.elastic.co/t/painless-script-error/306243/8 "2022-07-05T09:01:28Z")

</div>

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