# Mutate not converting text to integer

**URL:** <https://discuss.elastic.co/t/mutate-not-converting-text-to-integer/117256>\
**Category:** Logstash\
**Created:** [January 26, 2018, 7:21pm UTC](https://discuss.elastic.co/t/mutate-not-converting-text-to-integer/117256 "2018-01-26T19:21:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikebw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikebw/32/21766_2.png) [@mikebw](https://discuss.elastic.co/u/mikebw)\
**Post date:** [January 26, 2018, 7:21pm UTC](https://discuss.elastic.co/t/mutate-not-converting-text-to-integer/117256/1 "2018-01-26T19:21:13Z")

</div>

I'm trying to grok a field with regexp and convert it to an integer, but it's not converting to an integer.

```
if [type] == "server_log" {
  grok {
             match => ["message", ".*mediaDurationMs=(?<mediaDurationMs>\d+)"]
       }
  mutate {
    convert => { "mediaDurationMs" => "integer" }
  }
}

```

In Kibana I can see that the 'mediaDurationMs field exists now, but it's 't', not #.. What is the correct way to make sure the mediaDurationMs field is set to integer?

---

<div class="post-metadata">

**Author:** ![Vladi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vladi/32/108686_2.png) [@Vladi](https://discuss.elastic.co/u/Vladi)\
**Post date:** [January 27, 2018, 5:28am UTC](https://discuss.elastic.co/t/mutate-not-converting-text-to-integer/117256/2 "2018-01-27T05:28:59Z")

</div>

Hi Mike,

It's not a correct approach to manage field types, look into mapping. If your index mapping already has mediaDurationMs -\> string than logstash cannot overwrite it.

---

<div class="post-metadata">

**Author:** ![mikebw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikebw/32/21766_2.png) [@mikebw](https://discuss.elastic.co/u/mikebw)\
**Post date:** [January 28, 2018, 5:19pm UTC](https://discuss.elastic.co/t/mutate-not-converting-text-to-integer/117256/3 "2018-01-28T17:19:14Z")

</div>

I've tried setting a mapping for my logstash indexes and it still isn't taking:

```
{
    "template" : "logstash-*",
    "settings" : {
        "number_of_shards" : 2,
        "number_of_replicas" : 1,
        "refresh_interval" : "30s",
        "index.mapper.dynamic":true
    },
    "mappings": {
        "server_log": { 
    		"properties": { 
        		"mediaDurationMs": { "type": "long" }
    		}
      }
    }
}

```

What is the correct pattern for setting the data type of our log fields?

---

<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:** [January 28, 2018, 9:36pm UTC](https://discuss.elastic.co/t/mutate-not-converting-text-to-integer/117256/4 "2018-01-28T21:36:20Z")

</div>

> I've tried setting a mapping for my logstash indexes and it still isn't taking:

Did you create a new index after you uploaded this template? What mappings does that index have?

---

<div class="post-metadata">

**Author:** ![mikebw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikebw/32/21766_2.png) [@mikebw](https://discuss.elastic.co/u/mikebw)\
**Post date:** [January 29, 2018, 4:36am UTC](https://discuss.elastic.co/t/mutate-not-converting-text-to-integer/117256/5 "2018-01-29T04:36:22Z")

</div>

Looking at this mapping:

GET /logstash-2018.01.29/\_mapping

I can see that my mapping template is in place, because in the mapping its show as:

```
                "mediaDurationMs": {
                    "type": "long"
                },

```

However, in Kibana, it still shows as a string...

 ![53](https://us1.discourse-cdn.com/elastic/original/3X/0/8/08de5c26ad631866a47b60d02e3075f0c2445914.png)

---

<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:** [January 29, 2018, 6:57am UTC](https://discuss.elastic.co/t/mutate-not-converting-text-to-integer/117256/6 "2018-01-29T06:57:50Z")

</div>

Have you refreshed the fields in Kibana?

---

<div class="post-metadata">

**Author:** ![mikebw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikebw/32/21766_2.png) [@mikebw](https://discuss.elastic.co/u/mikebw)\
**Post date:** [January 29, 2018, 7:43am UTC](https://discuss.elastic.co/t/mutate-not-converting-text-to-integer/117256/7 "2018-01-29T07:43:25Z")

</div>

I did, and it looks like there is a conflict on that field.. I guess I need to grok to a new field and make sure the mapping is in place on the index and template before the field is created.

---

<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:** [February 26, 2018, 7:43am UTC](https://discuss.elastic.co/t/mutate-not-converting-text-to-integer/117256/8 "2018-02-26T07:43:39Z")

</div>

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