# Double Scripted Field gets fetched as string when filtering in a Dashboard

**URL:** https://discuss.elastic.co/t/double-scripted-field-gets-fetched-as-string-when-filtering-in-a-dashboard/281357
**Category:** Kibana
**Created:** [August 13, 2021, 12:55pm UTC](https://discuss.elastic.co/t/double-scripted-field-gets-fetched-as-string-when-filtering-in-a-dashboard/281357 "2021-08-13T12:55:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![DavidBrosIvent](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidbrosivent/32/92511_2.png) [@DavidBrosIvent](https://discuss.elastic.co/u/DavidBrosIvent)
#### Post date: [August 13, 2021, 12:55pm UTC](https://discuss.elastic.co/t/double-scripted-field-gets-fetched-as-string-when-filtering-in-a-dashboard/281357/1 "2021-08-13T12:55:10Z")

</div>

Hey guys,

I have a scripted field which returns a percentage value based on 2 keys in my documents. The scripted field is set to return 0 when the keys return a NaN value due to one of them being missing.

The script and formatting on this scripted field:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/0/a061a44b4b00cb046d4a38a3e19e6c2e575a98b2.png)

This, according to the error returns a dobule.

Here is what happens if I try to use the KQL filter on a dashboard using this key.

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

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/0/007938cdb364d21211151ae4cbe868f176e9d72d.png)

From what I understand, one of the values being compared is a string, which causes the comparison to fail. I fail to understand which of the values is the string (scripted field or my filter value).

Is there something wrong on my part?

We are running kibana 7.12-snapshot on a platinum license.

Thanks in advance and kind regards,

David.

---

<div class="post-metadata">

### Author: ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)
#### Post date: [August 17, 2021, 2:24pm UTC](https://discuss.elastic.co/t/double-scripted-field-gets-fetched-as-string-when-filtering-in-a-dashboard/281357/2 "2021-08-17T14:24:13Z")

</div>

Under `Stack management` -\> `Index patterns`, you can view the type for each field in an index pattern. Use this to figure out that types are returned for you fields. Then you can use [casting](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-casting.html) in your scripted field to cast the value to a number.

---

<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 14, 2021, 2:24pm UTC](https://discuss.elastic.co/t/double-scripted-field-gets-fetched-as-string-when-filtering-in-a-dashboard/281357/3 "2021-09-14T14:24:47Z")

</div>

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