convert string to double Elasticsearch

Asked

Viewed 29 times

-1

Hello, folks are in need of a help with Elasticsearch. I’m trying to do a script conversion, from a string field, to double, but unfortunately, I’m not getting it. the last script I did was this:

def cod=0;  if(String.valueOf(doc['codProduto.keyword'].value)!=null){ String sCod = doc['codProduto.keyword'].value; cod = Double.parseDouble(sCod);} return cod;

but returns this error

"caused_by" : { "type" means "illegal_state_exception", "Reason" : "A Document doesn’t have a value for a field! Use doc[]. size()==0 to check if a Document is Missing a field!"

but if I do the script that way:

def cod=0;  if(doc['codProduto'].size()>=0){ String sCod = doc['codProduto.keyword'].value; cod = Double.parseDouble(sCod);} return cod;

returns this error: ** "Text Fields are not Optimised for Operations that require per-Document field data like aggregations and Sorting, so These Operations are disabled by default. Please use a keyword field Instead. Alternatively, set fielddata=true on [codProduct] in order to load field data by uninverting the Inverted index. Note that this can use significant memory." **

1 answer

0

I managed to solve it, so I’m posting the answer in case anyone needs it

"int cod = 0; if(doc['codProduto.keyword'].empty){return 0;}else{cod = Integer.parseInt(doc['codProduto.keyword'].value);} return cod;"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.