Runtime field script String to Integer

Hi. I want to create a runtime field using this script:

if (doc.containsKey('price') ) { 
	return Integer.parseInt(doc['price.keyword'].value)
}

but I'm getting this error: Cannot cast from [int] to [void]. What does it actually mean?

Hi @kibanauser4

In runtime fields the way to return a value is to call emit( ... ) with the result.

In your case should be:

if (doc.containsKey('price') ) { 
	emit(Integer.parseInt(doc['price.keyword'].value));
}

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