Formatting jdbc-streaming filter result as a field instead of a list

Hi,

I trying to enrich the log with data (username) from postgres by user id.
However I didn't find a way to add the result as a field instead of a list. Is there a way to do so with the jdbc_streaming filter?

Actual result:

{
  "id" => "id1",
  "username" => [
    [0] {
      "username" => "user1"
    } 
  ]
}

Desired format:

{
  "id" => "id1",
  "username" => "user1"
}

The current pipeline:

input {
  http {
  }
}

filter {
  jdbc_streaming {
    jdbc_driver_library => "/.../postgresql-42.2.5.jar"
    jdbc_driver_class => "org.postgresql.Driver"
    jdbc_connection_string => "jdbc:postgresql://..."
    jdbc_user => "..."
    jdbc_password => "..."
    statement => "select username from users where id = :id"
    parameters => { "id" => "id"}
    target => "username"
  }
}

output {
  stdout {}
}

I believe that will always give you an array. You can replace the array with the first member using

mutate { replace => { "username" => "%{[username][0][username]}" } }
1 Like

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