Logstash 2.3.3 convert integers in list of json

Hi all,

I have a parsing problem with Logstash 2.3.3
I haven't found similar questions, apologize if this is a duplicate.
As input I have a file which every like is a json similar to this:

  {
    "field1": "foo",
    "field2": "100",
    "test":[
        {
            "name": "bar",
            "count":"13"
        },
        {
            "name": "asd",
            "count":"15"
        },
        {
            "name": "lol",
            "count":"7"
        }
    ],
    "field3": "300"
  }

I have the need to convert the string/numeric fields in integers. I use this configuration:

input {
  file {
    path => ["/path/to/file.json"]
    sincedb_path => "/path/to/db"
    start_position => "beginning"
    type => "foo"
    codec => "json"
  }
}

filter {
  if [type] == "foo" {
    mutate {
      convert => { "field2" => "integer" }
      convert => { "[test][count]" => "integer" }
      convert => { "field3" => "integer" }
    }
 ...
}

output {
  if [type] == "foo" {
    elasticsearch {
      hosts => ["127.0.0.1:9200"]
      index => "logstash-test"
    }
  }
}

The conversion on field2 and field3 is working correctly, the one on[test][count] no.
I can understand why this is not working, I am searching for a count field inside test and that key does not exist in test. I don't get any error by Logstash.
I can't find a solution, any idea?
Any help is appreciated.

Thanks!

I think you need to use a ruby filter for this kind of conversion.

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