i am trying to insert data from Elasticsearch to postgresql. it insert data in the postgresql but does not handle Blank value properly. As I am trying to insert black value in postgresql it fills the variable name of the Statement.
it is output in the postgresql: enter image description here it is my config file
input {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "input_data"
}
}
output {
jdbc {
connection_string => "jdbc:postgresql://hostname:5432/database"
username => "username"
password => "password"
driver_jar_path => "C:/postgresql-42.5.1.jar"
driver_class => "org.postgresql.Driver"
statement => [
"INSERT INTO data_post_two (inputdata,metric,source_table,output_column_alias,method) VALUES (?, ?, ?, ?, ?)",
"%{inputdata}",
"%{metric}",
"%{source_table}",
"%{output_column_alias}",
"%{method}"
]
}
}
That is expected. sprintf does not replace the value of %{fieldName} if the field does not exist. You will have to make sure the fields exist. A general way is surprisingly complicated because it has to handle boolean fields (if [field] {} cannot distinguish a boolean false from a non-existent field). Note that at the time of writing the best-practices documented by Elastic have a method that does not work because the copy and add_field have to be in seperate filters or the order of operations is incorrect...