# How to cast type in Scripted Field

**URL:** <https://discuss.elastic.co/t/how-to-cast-type-in-scripted-field/101397>\
**Category:** Kibana\
**Created:** [September 21, 2017, 9:42pm UTC](https://discuss.elastic.co/t/how-to-cast-type-in-scripted-field/101397 "2017-09-21T21:42:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adnil](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@adnil](https://discuss.elastic.co/u/adnil)\
**Post date:** [September 21, 2017, 9:42pm UTC](https://discuss.elastic.co/t/how-to-cast-type-in-scripted-field/101397/1 "2017-09-21T21:42:59Z")

</div>

I'm trying to create a scripted field so that I can perform some arithmetic.

I have the following field, which is currently a string: 'UCD-SNMP-MIB::memTotalReal.0.keyword'.

I want to convert that to an integer to do calculations so I went about to creating a scripted field and the Script syntax is:

cast:'('int')' memTotalReal = doc['UCD-SNMP-MIB::memTotalReal.0.keyword'].value;

but kept getting compile error.

Trying to use Painless scripting and following the doc but it's not helping.

---

<div class="post-metadata">

**Author:** ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)\
**Post date:** [September 22, 2017, 10:40pm UTC](https://discuss.elastic.co/t/how-to-cast-type-in-scripted-field/101397/2 "2017-09-22T22:40:29Z")

</div>

Only numeric, boolean, date, and geo\_point fields may be accessed. You will want to index the value as a numeric type.

---

<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 20, 2017, 10:41pm UTC](https://discuss.elastic.co/t/how-to-cast-type-in-scripted-field/101397/3 "2017-10-20T22:41:17Z")

</div>

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