# Convert fields of datatype text to int or float in Kibana

**URL:** https://discuss.elastic.co/t/convert-fields-of-datatype-text-to-int-or-float-in-kibana/194324
**Category:** Kibana
**Created:** [August 7, 2019, 8:43pm UTC](https://discuss.elastic.co/t/convert-fields-of-datatype-text-to-int-or-float-in-kibana/194324 "2019-08-07T20:43:41Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![dundundundun](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@dundundundun](https://discuss.elastic.co/u/dundundundun)
#### Post date: [August 7, 2019, 8:43pm UTC](https://discuss.elastic.co/t/convert-fields-of-datatype-text-to-int-or-float-in-kibana/194324/1 "2019-08-07T20:43:41Z")

</div>

Is there a way to convert fields ingested as datatype text to an integer or float in Kibana? It would be cool to be able to convert datatypes real time when creating a visual

---

<div class="post-metadata">

### Author: ![ppisljar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppisljar/32/11588_2.png) [@ppisljar](https://discuss.elastic.co/u/ppisljar)
#### Post date: [August 8, 2019, 8:31am UTC](https://discuss.elastic.co/t/convert-fields-of-datatype-text-to-int-or-float-in-kibana/194324/2 "2019-08-08T08:31:16Z")

</div>

You can convert data real time using scripted fields but the performance implications are huge (it will be a lot slower than having those fields indexed as correct data type)

> **[Using Painless in Kibana scripted fields](https://www.elastic.co/blog/using-painless-kibana-scripted-fields)**

> [@Painscript Script - cast String as Int?](https://discuss.elastic.co/t/painscript-script-cast-string-as-int/97034):
>
> We have a mapping issue that will be addressed soon for a field that should be an int but is presently a string. All values in the index should cast cleanly. Anyhow, in a pinch I wanted to aggregate some data on the field and thought creating a scripted field in K5 would be a temp solution. Can anyone point me in the right direction or provide a code example? I tried several things including (int)['doc.myfield'].value and also parseInt(string) as documented at [https://docs.oracle.com/javase/…](https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt%2Djava.lang.String%2D)

---

<div class="post-metadata">

### Author: ![dundundundun](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@dundundundun](https://discuss.elastic.co/u/dundundundun)
#### Post date: [August 8, 2019, 1:39pm UTC](https://discuss.elastic.co/t/convert-fields-of-datatype-text-to-int-or-float-in-kibana/194324/3 "2019-08-08T13:39:39Z")

</div>

I'm not understanding how to use scripted fields to convert a field into an integer or float.  
I've accessed the "Add scripted field" option under Management through the KB interface but do not get the syntax when typing in the script.

All I want to do is convert a field name, let's call it A from datatype keyword to datatype integer. And I want to convert another field name, let's call it B from datatype keyword to datatype float.

Thanks in advance!

---

<div class="post-metadata">

### Author: ![dundundundun](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@dundundundun](https://discuss.elastic.co/u/dundundundun)
#### Post date: [August 8, 2019, 3:48pm UTC](https://discuss.elastic.co/t/convert-fields-of-datatype-text-to-int-or-float-in-kibana/194324/4 "2019-08-08T15:48:11Z")

</div>

Alternatively, is there a way to convert values in a set of key-value pairs to an integer or float if it is indeed an int or float? That way I can ingest the fields into Kibana as integers/floats already rather than converting in the interface.

---

<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: [September 5, 2019, 3:48pm UTC](https://discuss.elastic.co/t/convert-fields-of-datatype-text-to-int-or-float-in-kibana/194324/5 "2019-09-05T15:48:13Z")

</div>

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