Why does this SIMPLE Kibana script not work?

Following right from the documentation:

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

 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

Yet I get an error as follows

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

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.

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:

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;

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