# How to Convert response-time from string to number in Kibana 5.1

**URL:** https://discuss.elastic.co/t/how-to-convert-response-time-from-string-to-number-in-kibana-5-1/80935
**Category:** Kibana
**Created:** [April 3, 2017, 1:19am UTC](https://discuss.elastic.co/t/how-to-convert-response-time-from-string-to-number-in-kibana-5-1/80935 "2017-04-03T01:19:25Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![cnallapati](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@cnallapati](https://discuss.elastic.co/u/cnallapati)
#### Post date: [April 3, 2017, 1:19am UTC](https://discuss.elastic.co/t/how-to-convert-response-time-from-string-to-number-in-kibana-5-1/80935/1 "2017-04-03T01:19:25Z")

</div>

Hello,

Log data sending response-time in string format. So it is not showing in aggregations unless it's in number format. How to convert string to number in Painless script Kibana or any other alternative options? Please advise.

Thanks,  
Chaitanya.

---

<div class="post-metadata">

### Author: ![eperry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eperry/32/551_2.png) [@eperry](https://discuss.elastic.co/u/eperry)
#### Post date: [April 3, 2017, 4:27am UTC](https://discuss.elastic.co/t/how-to-convert-response-time-from-string-to-number-in-kibana-5-1/80935/2 "2017-04-03T04:27:30Z")

</div>

Kibana can with Scripted fields but that is not really converting the field , it is creating a new dynamic field

You need to actually send it to Elastic as a Int and Set the Mapping of your index so the field is a int not string

for example if you groking the field "%{NUMER:responseTime:int} adding the int will make it an integer (you can use float if it is a decimal) or you can do it with the "MUTATE" filter to convert the field from string to whatever

for mappings, consult the Mapping documentation - Good to define your data  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)

you will need to re-index your data to change the mapping (or delete your data and send it in again)  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)

finally , and probably the most CPU intensive way  
[https://www.elastic.co/guide/en/kibana/current/scripted-fields.html](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html)

but I would recommend not doing that it will be slower and higher cpu.

I would Just make sure your data gets sent in to ELK in the right data format and have your mappings set appropriately.

---

<div class="post-metadata">

### Author: ![cnallapati](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@cnallapati](https://discuss.elastic.co/u/cnallapati)
#### Post date: [April 3, 2017, 5:24am UTC](https://discuss.elastic.co/t/how-to-convert-response-time-from-string-to-number-in-kibana-5-1/80935/3 "2017-04-03T05:24:45Z")

</div>

Hi Ed,

Thank you !!

Your options would work but our data is coming from AWS CloudWatch logs and I don't have control on Elasticsearch. Can I make string to int in painless script in Kibana? If so can you provide me an example.

Thanks,  
Chaitanya

---

<div class="post-metadata">

### Author: ![eperry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eperry/32/551_2.png) [@eperry](https://discuss.elastic.co/u/eperry)
#### Post date: [April 3, 2017, 7:17pm UTC](https://discuss.elastic.co/t/how-to-convert-response-time-from-string-to-number-in-kibana-5-1/80935/4 "2017-04-03T19:17:47Z")

</div>

Thinking about it a little bit more I think I over thought your issue.

You will have to change the Mappings of your index. If you mapping data says "response-time" is a int , Elastic will try to convert the "string" to int. and if your mapping says it is a "String" it will convert int's to strings. So even if you write a painless script it will remain the same type

Changing the mapping will help you on all future data, old history will have to be re-indexed to pickup the new changes but then you don't have to write a script to run all the time you get new data

If you provide me your index's current mapping I can help you make the change  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html)

---

<div class="post-metadata">

### Author: ![cnallapati](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@cnallapati](https://discuss.elastic.co/u/cnallapati)
#### Post date: [April 4, 2017, 3:25pm UTC](https://discuss.elastic.co/t/how-to-convert-response-time-from-string-to-number-in-kibana-5-1/80935/5 "2017-04-04T15:25:27Z")

</div>

Hi Ed, Thank you for your time and advise.

In index, getting response-time as string. Please advise how to mapping it to int.  
{  
"cwl-2017.03.21": {  
"mappings": {  
"retail-rtmstack-dev-logsgroup": {  
"properties": {  
"@id": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"@log\_group": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"@log\_stream": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"@message": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"@owner": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"@timestamp": {  
"type": "date"  
},  
"response-time": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},

Thanks,  
Chaitanya

---

<div class="post-metadata">

### Author: ![eperry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eperry/32/551_2.png) [@eperry](https://discuss.elastic.co/u/eperry)
#### Post date: [April 4, 2017, 3:44pm UTC](https://discuss.elastic.co/t/how-to-convert-response-time-from-string-to-number-in-kibana-5-1/80935/6 "2017-04-04T15:44:39Z")

</div>

just change the type for your field from text to "Integer" or if it is a float to float  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html)

Btw, now you have to make this file a template , its bacically just adding the "template matching" and any additional information you need when the index is created

[https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html)

```auto
  "template" : "<indexname>*",
  "mappings" : {

```

and then load your mapping back in to the index  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html)

---

<div class="post-metadata">

### Author: ![cnallapati](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@cnallapati](https://discuss.elastic.co/u/cnallapati)
#### Post date: [April 5, 2017, 9:21pm UTC](https://discuss.elastic.co/t/how-to-convert-response-time-from-string-to-number-in-kibana-5-1/80935/7 "2017-04-05T21:21:42Z")

</div>

Hi Ed,

Thank you for the details. I gone through the links but I am missing something. If you don't mind, can you provide step by step with the index data.

Thanks,  
Chaitanya.

---

<div class="post-metadata">

### Author: ![eperry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eperry/32/551_2.png) [@eperry](https://discuss.elastic.co/u/eperry)
#### Post date: [April 6, 2017, 4:32pm UTC](https://discuss.elastic.co/t/how-to-convert-response-time-from-string-to-number-in-kibana-5-1/80935/8 "2017-04-06T16:32:09Z")

</div>

I am not able to write a full tutorial on this for you, you may want to try googling are reading the rest of the docs.  
It is pretty easy to do but it is a wide subject

I did a quick google and saw this

> **[​Little Logstash Lessons: Using Logstash to help create an Elasticsearch mapping...](https://www.elastic.co/blog/logstash_lesson_elasticsearch_mapping)**
>
> How to use Logstash together with Elasticsearch to create custom mapping templates. Improve your Elasticsearch storage and performance!

or maybe this too

> **[Logstash mapping tutorial](http://www.pipebug.com/elasticsearch-logstash-kibana-4-mapping-4.html)**
>
> Logstash mapping template example, installation and detailed description. Mapping benefits.

---

<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: [May 4, 2017, 4:32pm UTC](https://discuss.elastic.co/t/how-to-convert-response-time-from-string-to-number-in-kibana-5-1/80935/9 "2017-05-04T16:32:20Z")

</div>

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