# Why does this SIMPLE Kibana script not work?

**URL:** <https://discuss.elastic.co/t/why-does-this-simple-kibana-script-not-work/327228>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [March 7, 2023, 8:14pm UTC](https://discuss.elastic.co/t/why-does-this-simple-kibana-script-not-work/327228 "2023-03-07T20:14:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gyannea](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@gyannea](https://discuss.elastic.co/u/gyannea)\
**Post date:** [March 7, 2023, 8:14pm UTC](https://discuss.elastic.co/t/why-does-this-simple-kibana-script-not-work/327228/1 "2023-03-07T20:14:45Z")

</div>

Following right from the documentation:

hubEvent.rssi is a String like '-98 dBm'  
I want to return a number

```auto
 def rssi = doc['hubEvent.rssi.keyword'].value;
if (rssi != null)
{
    int lastdBIndex = rssi.lastIndexOf('dB');
    return Double.parseDouble(rssi.substring(lastdBIndex));
}
return null;

```

Following documentation here almost line for line

> **[Using Painless in Kibana scripted fields](https://www.elastic.co/blog/using-painless-kibana-scripted-fields)**

Yet I get an error as follows

```auto
Error executing Painless script: ' def rssi = doc['hubEvent.rssi.keyword'].value; ...'.
org.elasticsearch.index.fielddata.ScriptDocValues$Strings.get(ScriptDocValues.java:494)
org.elasticsearch.index.fielddata.ScriptDocValues$Strings.getValue(ScriptDocValues.java:508)
rssi = doc['hubEvent.rssi.keyword'].value;
                                   ^---- HERE

```

I have played around with all kinds of combos (String instead of 'def' which I don't understand but its in the docs with no explanation). In total frustration I just returned a string instead of a number where I just did

```auto
return doc['hubEvent.rssi.keyword'].value;

```

Worked like a charm. !!!???? !!! WTF???

I was hoping today's (March 7 Elastithon would provide some help). But it was all promotion. Kibana became a lot more difficult to work with after updating from 7.1.1 to 7.10.2. A lot more clicking to do the same things. Frustrating when you have issues like this to retry again and again.

---

<div class="post-metadata">

**Author:** ![gyannea](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@gyannea](https://discuss.elastic.co/u/gyannea)\
**Post date:** [March 7, 2023, 9:46pm UTC](https://discuss.elastic.co/t/why-does-this-simple-kibana-script-not-work/327228/2 "2023-03-07T21:46:00Z")

</div>

Basically the answer is that the documentation is wrong and inconsistent, and the error messages generated by Kibana don't help. There was one attempt where I got a different error message that did help as it clued me in to the use of .size() for the non-existence check for strings and numbers. The documentation had a different check for strings (doesn't work).

This script is what worked:

```auto
if (doc['hubEvent.rssi.keyword'].size() > 0)
{
    String rssi = doc['hubEvent.rssi.keyword'].value;
    int dbIndex = rssi.lastIndexOf('d');
    rssi = rssi.substring(0, dbIndex);
    return Double.parseDouble(rssi);
}
return null;

```

---

<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:** [April 4, 2023, 9:46pm UTC](https://discuss.elastic.co/t/why-does-this-simple-kibana-script-not-work/327228/3 "2023-04-04T21:46:31Z")

</div>

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