Scripted field - painless converting to float

Hi, i am trying to get the following to work via kibana in a scripted field but all it causes is errors (not very descriptive), pretty sure this is an elasticsearch misunderstanding so posting it here.

example events [{ 'name': 'Name One', 'cash': 100}, { 'name': 'Name One', 'cash': 24}, { 'name': 'Name Two', 'cash': 112}]

def rtp = ['Name One': 0.986f, 'Name Two': 0.94f];
def name = doc['name'].value;
def rtp_val = rtp[name];

def win_pct = 1 - rtp_val; // errors
def cash = doc['cash'].value;
def win_amt = cash * win_pct; // errors but mainly due to first one.
return win_amt;

Only thing i can think of is that the error is something related to types so looked around trying to find a way to convert to floats, the only example i did end up finding doesn't work and is quite old, pretty sure it's a groovy example.

Float.parseFloat(rtp_val); // errors

Any one know how to achieve this ?

P.S would be nice to have kibana show an example output from a random event

Thanks

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