# Parse a String to an Int

**URL:** <https://discuss.elastic.co/t/parse-a-string-to-an-int/76621>\
**Category:** Logstash\
**Created:** [February 27, 2017, 1:07pm UTC](https://discuss.elastic.co/t/parse-a-string-to-an-int/76621 "2017-02-27T13:07:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)\
**Post date:** [February 27, 2017, 1:07pm UTC](https://discuss.elastic.co/t/parse-a-string-to-an-int/76621/1 "2017-02-27T13:07:36Z")

</div>

I am new to the whole ELK. I have a field that I get through a Json that is called "msgDeliveryTime" who I get as a String even though it is an Integer. So I tried to learn the "GROK" and I improvised the following:

```
input {
  beats {
    port => 5044
       }

  }
filter {
  mutate {
    convert => { "msgDeliveryTime" => "integer" }
  }
}
output {
  elasticsearch { hosts => ["192.1.1.1:9200"] }

}

```

This did not budge the output at all.  
I know that this is basics but for some reason I am not able to google it 😑 . Any help will be great!

P.S.  
My real goal is make "msgDeliveryTime" as my timestamp (it is given as mm)

---

<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:** [February 27, 2017, 1:10pm UTC](https://discuss.elastic.co/t/parse-a-string-to-an-int/76621/2 "2017-02-27T13:10:33Z")

</div>

Comment out your elasticsearch output and insert a `stdout { codec => rubydebug }` output instead. What results do you get in your log, i.e. what do your events really look like?

A possible problem is that the `msgDeliveryTime` field already has been mapped as a string, and the mapping of fields can't be changed without reindexing.

---

<div class="post-metadata">

**Author:** ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)\
**Post date:** [February 27, 2017, 1:40pm UTC](https://discuss.elastic.co/t/parse-a-string-to-an-int/76621/3 "2017-02-27T13:40:38Z")

</div>

Thank you for the quick reply!  
Well I checked using "stdout { codec =\> rubydebug } " the script works like before.

For confidential reasons my company might not want me to put here a log 🙂 but is combined something like this:

{"dataCoding":0,"from":"123","identifier":"123","longMessageSequenceNumber":123" ... (and many more fields like this) ... }

What does it mean that it is mapped?

---

<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:** [February 27, 2017, 1:43pm UTC](https://discuss.elastic.co/t/parse-a-string-to-an-int/76621/4 "2017-02-27T13:43:57Z")

</div>

> For confidential reasons my company might not want me to put here a log

Then obfuscate the parts that are sensitive. I'm interested in exactly what the `msgDeliveryTime` field looks like.

> What does it mean that it is mapped?

Please read about mappings in the Elasticsearch documentation.

---

<div class="post-metadata">

**Author:** ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)\
**Post date:** [February 27, 2017, 1:48pm UTC](https://discuss.elastic.co/t/parse-a-string-to-an-int/76621/5 "2017-02-27T13:48:50Z")

</div>

`{"recordType":"MT","callingNumber":"123","callingImsi":"","callingMsc":"","billable":"","calledNumber":"123","calledImsi":"","calledMsc":"","msgSubmissionTime":"1484752652741","clientId":"","gmt1":"-1","msgDeliveryTime":"0","originatingProtocol":"MAP","gmt2":"-1","campignId":"","channel":"","destinationProtocol":"MAP","terminationCause":"STRING","transactionId":"123","msgLength":"0","concatenated":"FALSE","concatenatedFrom":"1","sequence":"0","priority":"","deferred":"","numOfAttemp":"0"}`

Sorry about the confusion but I need msgSubmissionTime field as a long or int (I tried on msgSubmissionTime and also did not succeed)

I will look at mapping

---

<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:** [February 27, 2017, 3:15pm UTC](https://discuss.elastic.co/t/parse-a-string-to-an-int/76621/6 "2017-02-27T15:15:43Z")

</div>

Well, at least Logstash 2.4.0 is able to convert the field:

```nohighlight
$ cat test.config 
input { stdin { codec => json_lines } }
output { stdout { codec => rubydebug } }
filter {
  mutate {
    convert => ["msgSubmissionTime", "integer"]
  }
}
$ echo '{"msgSubmissionTime": "1484752652741"}' | /opt/logstash/bin/logstash -f test.config
Settings: Default pipeline workers: 8
Pipeline main started
{
    "msgSubmissionTime" => 1484752652741,
             "@version" => "1",
           "@timestamp" => "2017-02-27T15:14:25.741Z",
                 "host" => "lnxolofon"
}
Pipeline main has been shutdown
stopping pipeline {:id=>"main"}

```

---

<div class="post-metadata">

**Author:** ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)\
**Post date:** [February 27, 2017, 3:40pm UTC](https://discuss.elastic.co/t/parse-a-string-to-an-int/76621/7 "2017-02-27T15:40:07Z")

</div>

I see, well I am using Logstash 5.2.0, but I do not think that this is the problem.

It is probably with a configuration between filebeat logstash and ES!

Many thanks!

---

<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:** [March 27, 2017, 3:40pm UTC](https://discuss.elastic.co/t/parse-a-string-to-an-int/76621/8 "2017-03-27T15:40:21Z")

</div>

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