# Nested json field mutate string to number

**URL:** https://discuss.elastic.co/t/nested-json-field-mutate-string-to-number/110846
**Category:** Logstash
**Created:** [December 8, 2017, 12:44pm UTC](https://discuss.elastic.co/t/nested-json-field-mutate-string-to-number/110846 "2017-12-08T12:44:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![fpunzo](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@fpunzo](https://discuss.elastic.co/u/fpunzo)
#### Post date: [December 8, 2017, 12:44pm UTC](https://discuss.elastic.co/t/nested-json-field-mutate-string-to-number/110846/1 "2017-12-08T12:44:50Z")

</div>

Hello, I'm trying to convert a nested json field from a string to an integer. I've tried everything I've found on the web. I'm hoping you can give me some direction as to what I'm doing wrong. I'm trying to convert the resp\_time\_ms field to integer. The server that is running the data and config below is a Windows Server 2012 and the server receiving the data is a RedHat LInux box. The data and config below work to put data into Elasticsearch but the resp\_time\_ms goes in as a string. Also, I've tried deleting the index and also tried creating a new index by changing the indexname below.

Here is my data :  
{"test\_results":{"test":{"test\_id":"1a21db7d-21fb-4f2f-897f-1fde26531597","type":"webpage","application\_id":"RestServices","component\_id":"","env\_name":"INT","test\_date":"2017-11-1514:21:21:000","pass\_fail":"passed","webpage\_test":{"test\_id":"1a21db7d-21fb-4f2f-897f-1fde26531597","dashboard":"DB\_Trx\_PageLoad","webpage\_result":[{"test\_id":"1a21db7d-21fb-4f2f-897f-1fde26531597","page\_name":"TRX\_Rest\_1","time\_stamp":"2017-11-1514:21:21:000","resp\_time\_ms":"31.000","status":"passed"},{"test\_id":"1a21db7d-21fb-4f2f-897f-1fde26531597","page\_name":"TRX\_Rest\_2","time\_stamp":"2017-11-1514:21:21:000","resp\_time\_ms":"609.000","status":"passed"},{"test\_id":"1a21db7d-21fb-4f2f-897f-1fde26531597","page\_name":"TRX\_Rest\_3","time\_stamp":"2017-11-1514:21:21:000","resp\_time\_ms":"47.000","status":"passed"},{"test\_id":"1a21db7d-21fb-4f2f-897f-1fde26531597","page\_name":"TRX\_Rest\_4","time\_stamp":"2017-11-1514:21:21:000","resp\_time\_ms":"16.000","status":"passed"},{"test\_id":"1a21db7d-21fb-4f2f-897f-1fde26531597","page\_name":"TRX\_Rest\_5","time\_stamp":"2017-11-1514:21:21:000","resp\_time\_ms":"31.000","status":"passed"}]}}}}

Here is my config :  
input  
{  
file  
{  
type =\> "DeploymentScoring"  
path =\> ["D:/DeployTest/AutomatedDeployTestResults/INT/input/\*.json"]  
sincedb\_path =\> "D:/DeployTest/AutomatedDeployTestResults/INT/input/DplyTestSinceDB"  
start\_position =\> "beginning"  
}  
}  
filter{  
json{  
source =\> "message"  
}  
date {  
match =\> ["test\_date", "yyyy-MM-dd HH:mm:ss.SSSZ"]  
target =\> "@timestamp"  
}  
mutate {  
convert =\> ["%[test\_results][test][webpage\_test][webpage\_result][resp\_time\_ms]", "integer" ]  
}  
}  
output  
{  
elasticsearch {  
hosts =\> "hostname:9200"  
manage\_template =\> false  
index =\> "indexname"  
document\_type =\> "doctype"  
}  
}

Thanks in advance.

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [December 8, 2017, 2:02pm UTC](https://discuss.elastic.co/t/nested-json-field-mutate-string-to-number/110846/2 "2017-12-08T14:02:44Z")

</div>

> convert =\> ["%[test\_results][test][webpage\_test][webpage\_result][resp\_time\_ms]", "integer" ]

Drop the "%".

I think it still won't work since the `webpage_result` subfield contains an array. In that case you'll have to use a ruby filter.

---

<div class="post-metadata">

### Author: ![fpunzo](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@fpunzo](https://discuss.elastic.co/u/fpunzo)
#### Post date: [December 8, 2017, 2:38pm UTC](https://discuss.elastic.co/t/nested-json-field-mutate-string-to-number/110846/3 "2017-12-08T14:38:05Z")

</div>

Thanks Magnus. Ya I tried it with and without the %. I'll do some research on the Ruby filter. Thanks for the help.

---

<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: [January 5, 2018, 2:38pm UTC](https://discuss.elastic.co/t/nested-json-field-mutate-string-to-number/110846/4 "2018-01-05T14:38:13Z")

</div>

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