Cast into script failing


(Bruno Dlb) #1

Hi all,

I'm writing a script for an upsert and i'm having a facing one issue on casting a field.

Basically my field is a String but when myString.isNumber() i would like to cast it Integer with the function Integer.parseInt in order to do a comparison with another field but i'm always receiving the following error :

error":"ElasticsearchIllegalArgumentException[failed to execute script]; nested: GroovyScriptExecutionException[GroovyCastException[Cannot cast object '70' with class 'java.lang.String' to class 'java.lang.Integer']]; ","status":400

Any idea on what can be the issue, here is a part of code :

		if ( "${Integer.parseInt(sub.status)}" < lower){
			lower = "${Integer.parseInt(sub.status)}";
			subId = sub.erpNumber;
		}

(Adrien Grand) #2

I did not try out but I suspect lower is an Integer so lower = "${Integer.parseInt(sub.status)}";fails because of the enclosing quotes?


(Bruno Dlb) #3

thanks for your reply i have also tested directly with Integer.parseInt without success :frowning:


(Adrien Grand) #4

Did you get the same error or a different one? Wouldn't this work?

		if (Integer.parseInt(sub.status) < lower){
			lower = Integer.parseInt(sub.status);
			subId = sub.erpNumber;
		}

(Bruno Dlb) #5

Exactly the same.


(Bruno Dlb) #6

Any idea from where it could come from ? by the way i'm on ES 1.4


(Adrien Grand) #7

Could you build a recreation of your issue using curl or Sense? (including index creation, adding documents, and running a query with this script)


(system) #8