# Runtime field script String to Integer

**URL:** <https://discuss.elastic.co/t/runtime-field-script-string-to-integer/315678>\
**Category:** Kibana\
**Created:** [October 3, 2022, 10:27am UTC](https://discuss.elastic.co/t/runtime-field-script-string-to-integer/315678 "2022-10-03T10:27:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kibanauser4](https://avatars.discourse-cdn.com/v4/letter/k/ecd19e/32.png) [@kibanauser4](https://discuss.elastic.co/u/kibanauser4)\
**Post date:** [October 3, 2022, 10:27am UTC](https://discuss.elastic.co/t/runtime-field-script-string-to-integer/315678/1 "2022-10-03T10:27:51Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [October 3, 2022, 12:21pm UTC](https://discuss.elastic.co/t/runtime-field-script-string-to-integer/315678/2 "2022-10-03T12:21:15Z")

</div>

Hi @kibanauser4

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

In your case should be:

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

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 31, 2022, 12:21pm UTC](https://discuss.elastic.co/t/runtime-field-script-string-to-integer/315678/3 "2022-10-31T12:21:25Z")

</div>

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