# Mutate filter throws NumberFormat Exception for no reason

**URL:** <https://discuss.elastic.co/t/mutate-filter-throws-numberformat-exception-for-no-reason/69597>\
**Category:** Logstash\
**Created:** [December 20, 2016, 4:35pm UTC](https://discuss.elastic.co/t/mutate-filter-throws-numberformat-exception-for-no-reason/69597 "2016-12-20T16:35:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbrandstaedter](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@rbrandstaedter](https://discuss.elastic.co/u/rbrandstaedter)\
**Post date:** [December 20, 2016, 4:35pm UTC](https://discuss.elastic.co/t/mutate-filter-throws-numberformat-exception-for-no-reason/69597/1 "2016-12-20T16:35:04Z")

</div>

I recently migrated from 3.1 to 5.1 and wanted to continue to use my logstash filter/output configuration. Since the event API changed I adopted those but soon realised that the mutate filter is suddenly throwing excpetions that haven't been there before!

In 3.1 I had a filter that looked like this:

```
if ( [businessTransactions][type] == 1 ) {
  mutate {
    add_field => {
      "clientTime" => '%{[businessTransactions][occurrences][clientTime]}'
      "serverTime" => '%{[businessTransactions][occurrences][serverTime]}'
    }
  }
}

```

This gave me float values in the fields that were nicely written to influxDB afterwards.  
First I realised that before there was nice automatic conversion to float and with 5.1 these float values were written as string now. So i added a mutate convert filter

```
if ( [businessTransactions][type] == 1 ) {
  mutate {
    add_field => {
      "clientTime" => '%{[businessTransactions][occurrences][clientTime]}'
      "serverTime" => '%{[businessTransactions][occurrences][serverTime]}'
    }
  }
  mutate {
    convert => {
      "serverTime" => "float"
      "clientTime" => "float"
    }
  }
}

```

Doing so 'sometimes' gives me a Exception in syslog. I can guarantee that the values in clientTime are always numbers and no strings. This is the top stacktrace:

```
Exception in thread "[main]>worker3" java.lang.NumberFormatException: For input string: "clientTime"
#011at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
#011at java.lang.Integer.parseInt(Integer.java:580)
#011at java.lang.Integer.parseInt(Integer.java:615)
#011at org.logstash.Accessors.fetch(Accessors.java:130)
#011at org.logstash.Accessors.get(Accessors.java:20)
#011at org.logstash.Event.getUnconvertedField(Event.java:160)
#011at org.logstash.Event.getField(Event.java:150)
#011at org.logstash.KeyNode.evaluate(KeyNode.java:26)
#011at org.logstash.StringInterpolation.evaluate(StringInterpolation.java:47)
#011at org.logstash.Event.sprintf(Event.java:294)
#011at org.logstash.ext.JrubyEventExtLibrary$RubyEvent.ruby_sprintf(JrubyEventExtLibrary.java:200)
...
#011at rubyjit.LogStash::Filters::Mutate$$filter_7ece4ecf2c9d8324f6c4933fda087138f0104c701442407170. __file__ (/usr/share/logstash/vendor/bundle/jruby/1.9/gems/logstash-filter-mutate-3.1.3/lib/logstash/filters/mutate.rb:216)
#011at rubyjit.LogStash::Filters::Mutate$$filter_7ece4ecf2c9d8324f6c4933fda087138f0104c701442407170. __file__ (/usr/share/logstash/vendor/bundle/jruby/1.9/gems/logstash-filter-mutate-3.1.3/lib/logstash/filters/mutate.rb)
#011at org.jruby.internal.runtime.methods.JittedMethod.call(JittedMethod.java:201)
#011at org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:177)
#011at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:183)
#011at rubyjit.LogStash::Filters::Base$$do_filter_8e8403dcfdf01a35ffca12ed35ec4e79455489071442407170. __file__ (/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb:145)
#011at rubyjit.LogStash::Filters::Base$$do_filter_8e8403dcfdf01a35ffca12ed35ec4e79455489071442407170. __file__ (/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb)
#011at org.jruby.internal.runtime.methods.JittedMethod.call(JittedMethod.java:201)

```

So I added the conversion and field creation directly in a ruby filter:

```
if ( [businessTransactions][type] == 1 ) {
  ruby {
    code => "
      unless event.get('[businessTransactions][occurrences][clientTime]').nil?
      event.set('clientTime',sprintf('%.4f',event.get('[businessTransactions][occurrences][clientTime]')).to_f)
    end
      unless event.get('[businessTransactions][occurrences][serverTime]').nil?
      event.set('serverTime',sprintf('%.4f',event.get('[businessTransactions][occurrences][serverTime]')).to_f)
    end
    "
  }
}

```

This seems to work but I have other filters where I now get NumberFormat Exceptions that do not make sense at all. e.g. this mutate:

```
mutate {
  add_field => {
    "tagging_values" => "%{[businessTransactions][occurrences][dimensions]}"
    "application" => "%{[businessTransactions][application]}"
    "businesstransaction" => "%{[businessTransactions][name]}"
    "systemprofile" => "%{[businessTransactions][systemProfile]}"
    "project" => "%{[businessTransactions][systemProfile]}"
    "responsetime" => '%{[businessTransactions][occurrences][responseTime]}'
    "time" => "%{[businessTransactions][occurrences][startTime]}"
    "resultmeasure_names" => "%{[businessTransactions][measureNames]}"
    "resultmeasure_values" => "%{[businessTransactions][occurrences][values]}"
  }
}

```

It now also throws an exception after I've fixed the above.:

```
Exception in thread "[main]>worker1" java.lang.NumberFormatException: For input string: "dimensions"
#011at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
#011at java.lang.Integer.parseInt(Integer.java:580)
#011at java.lang.Integer.parseInt(Integer.java:615)
#011at org.logstash.Accessors.fetch(Accessors.java:130)
#011at org.logstash.Accessors.get(Accessors.java:20)
#011at org.logstash.Event.getUnconvertedField(Event.java:160)
#011at org.logstash.Event.getField(Event.java:150)
#011at org.logstash.KeyNode.evaluate(KeyNode.java:26)

```

The data I'm feeding into logstash is sane and correct, as soon as I hook up my event source to logstash 3.1 everything works fine.

Any ideas? I've seen that there are other posts about mutate filter problems...

Thanks,  
Reinhard

---

<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 22, 2016, 7:00am UTC](https://discuss.elastic.co/t/mutate-filter-throws-numberformat-exception-for-no-reason/69597/2 "2016-12-22T07:00:08Z")

</div>

Please show an example event, preferably using a `stdout { codec => rubydebug }` output.

---

<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 19, 2017, 7:00am UTC](https://discuss.elastic.co/t/mutate-filter-throws-numberformat-exception-for-no-reason/69597/3 "2017-01-19T07:00:26Z")

</div>

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