Runtime Field Convert String to Number

Is there a way to convert string / text to a number in a runtime field script? We have data that is getting ingested into Elastic as keyword / text fields, but I need to convert that data at runtime from a string to number for visualization calculations.

I have tried multiple iterations of this simple script, but it always errors out since the keyword is text, and the runtime field will be a Long. I get an error "class_cast_exception: cannot implicitly cast def [java.lang.String] to long"

if (doc['somekey_value.keyword'].size() > 0) {
    def value = doc['somekey_value.keyword'].value;
    if (value != null) {
	        emit(value);
	        return;
    }
}
else {
	emit(0)
}

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