Cast into script failing

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;
		}

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

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

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;
		}

Exactly the same.

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

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