Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting JSON Decimal to String yields scientific ("E") notation result #92

Open
talvey opened this issue Feb 27, 2017 · 2 comments
Open

Comments

@talvey
Copy link

talvey commented Feb 27, 2017

Given a JSON message with a decimal field value, converting that target value to a string will result in scientific "E" notation. While this isn't exactly a bug, I'd call it an unexpected result.

To recreate, pass the following simple JSON document to logstash

{
  "data" : {
    "decimal1" : 5.1
  }
}

And then use the following filter section

filter {
    json {
        source => "message"
    }
    mutate {
        convert => { "[data][decimal1]" => "string"}
    }
}

The result is "decimal1" => "0.51E1"

My guess -- the cause is the underlying java json parsing library defaulting decimal fields to Java BigDecimal, which gets translated to a Ruby BigDecimal -- calling to_s on the Ruby BigDecimal yields the "0.51E1".

@bobrien27
Copy link

Anyone else having this issue? Tried multiple java 15 versions and ELK Stacks 7.12.x/7.13.0 combinations, but when using mutate { convert => { ["field"] => "string"}} I get the same results with 11.11 => "0.1111e2".

@bobrien27
Copy link

mutate { add_field => { "placeholder" => "%{float_number}"} }
mutate { convert => ["float_number","string"]}
ruby { code => ' event.set("float_number", event.get("placeholder").slice(0..-3)) '}
mutate { remove_field => [ "placeholder" ] }

My temporary workaround, if anyone has a fix or better solution any help is greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants