# Convert String to float failed

**URL:** https://discuss.elastic.co/t/convert-string-to-float-failed/32232
**Category:** Logstash
**Created:** [October 15, 2015, 3:23am UTC](https://discuss.elastic.co/t/convert-string-to-float-failed/32232 "2015-10-15T03:23:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Enniu\_51](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enniu_51/32/5310_2.png) [@Enniu\_51](https://discuss.elastic.co/u/Enniu_51)
#### Post date: [October 15, 2015, 3:23am UTC](https://discuss.elastic.co/t/convert-string-to-float-failed/32232/1 "2015-10-15T03:23:47Z")

</div>

My logstash config:

```
filter {
  grok {
    match => {"stack_trace" => "%{JAVACLASS:exception_class}: \[%{DATA:error_level}\]\[%{BASE10NUM:error_code}\]-%{GREEDYDATA:error_message}"}
  }
  grok {
    match => {"message" => "%{DATA:geo_message}: carrier=%{DATA:carrier}, province=%{DATA:province}, city=%{DATA:city}, location=%{BASE10NUM:latitude},%{BASE10NUM:longitude}"}
    add_tag => ["geo_parse_succeed"]
  }
  if "geo_parse_succeed" in [tags] {
    mutate {
      add_field => {"geoip.location" => ["%{longitude}","%{latitude}"]}
      convert => { "geoip.location" => "float" }
    }
  }
}

```

And the log:

```
  "_source": {
    "@timestamp": "2015-10-15T11:14:40.547+08:00",
    "@version": 1,
    "message": "New crawl task: carrier=CARRIER, province=provY, city=cityX, location=45.7656666,126.6160584",
    "level": "INFO",
    "level_value": 20000,
    "carrier": "CARRIER",
    "remoteIp": "127.0.0.1",
    "province": "provY",
    "tid": "40562a0a-558f-4a4a-b664-b5ef1a3cd565",
    "service": "crawler",
    "host": "192.168.5.130:56020",
    "type": "redis-input",
    "tags": [
      "_grokparsefailure",
      "geo_parse_succeed"
    ],
    "geo_message": "New crawl task",
    "city": "cityX",
    "latitude": "45.7656666",
    "longitude": "126.6160584",
    "geoip.location": [
      "126.6160584",
      "45.7656666"
    ]
  },

```

As you see, the element of `geoip.location` is still string(not float), but I don't see any error log from logstash..

---

<div class="post-metadata">

### Author: ![Enniu\_51](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enniu_51/32/5310_2.png) [@Enniu\_51](https://discuss.elastic.co/u/Enniu_51)
#### Post date: [October 15, 2015, 4:07am UTC](https://discuss.elastic.co/t/convert-string-to-float-failed/32232/2 "2015-10-15T04:07:15Z")

</div>

> [@Enniu\_51](#):
>
> convert =\> { "geoip.location" =\> "float" }

I also tried:

```
convert => ["geoip.location", "float"]

```

it doesn't works, either.

---

<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: [October 15, 2015, 6:10am UTC](https://discuss.elastic.co/t/convert-string-to-float-failed/32232/3 "2015-10-15T06:10:35Z")

</div>

> ```
> mutate {
> 
> ```

```
  add_field => {"geoip.location" => ["%{longitude}","%{latitude}"]}
  convert => { "geoip.location" => "float" }
}

```

I'm not sure if these directives are necessarily processed in order. I'd try splitting this in two mutate filters (one with `add_field` and one with `convert`) just to make sure the field is added before we attempt to convert its type.

---

<div class="post-metadata">

### Author: ![Enniu\_51](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enniu_51/32/5310_2.png) [@Enniu\_51](https://discuss.elastic.co/u/Enniu_51)
#### Post date: [October 15, 2015, 7:27am UTC](https://discuss.elastic.co/t/convert-string-to-float-failed/32232/4 "2015-10-15T07:27:21Z")

</div>

Wow, it works after I split it to two `mutate`! Thank you very much!

It bothers me for a long time.

---

<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: [July 6, 2017, 5:26am UTC](https://discuss.elastic.co/t/convert-string-to-float-failed/32232/5 "2017-07-06T05:26:28Z")

</div>


