Conditional inside filter error

Hi, im trying to parse a field only if its a number, from time to time I get the string "n/a" instead of a number so I write this conditional inside a filter, but doesnt work.

I also have another mutate { convert => {}} inside the same filter, I dont know if this could be a problem

                 if [physmemperc] != "n/a"{ mutate { convert => {"physmemperc" => "float" }}}
                mutate {

                        convert => {
                                "virtmemperc" => "float"
                                "pages" => "float"
                                "id" => "integer"
                        }


The error

error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse field [physmemperc] of type [float] in document with id 'B4bfpXAB4khdA4bte5Fb'. Preview of field's value: 'n/a'", "caused_by"=>{"type"=>"number_format_exception", "reason"=>"For input string: \"n/a\""}}}}}

I think you could remove the field when it's "n/a", then it would appear as "missing" when indexed.

1 Like

Something like this?

  if [physmemperc] == "n/a" {
    mutate {
      remove_field => [ "physmemperc" ]
    }

there will not be a problem if I try to convert a non existing field?

            mutate {

                    convert => {
                            "virtmemperc" => "float"
                            "pages" => "float"
                            "id" => "integer"
                            "physmemperc" =>  "float"
                    }

Add an else to mutate convert that field here, then remove the convert for that field below.

1 Like

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