[英]Null value not inserted in Postgresql by Logstash
我正在尝试将数据从 Elasticsearch 插入到 postgresql。它在 postgresql 中插入数据但没有正确处理空白值。 当我试图在 postgresql 中插入黑色值时,它填充了语句的变量名。
它是postgresql中的output:在此处输入图像描述这是我的配置文件
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}"
]
}
}
这是意料之中的。 如果字段不存在,sprintf 不会替换 %{fieldName} 的值。 您必须确保这些字段存在。 通用方法出奇地复杂,因为它必须处理 boolean 个字段(如果 [field] {} 无法区分 boolean false 和不存在的字段)。 请注意,在撰写本文时,Elastic记录的最佳实践有一种方法不起作用,因为 copy 和 add_field 必须位于单独的过滤器中,或者操作顺序不正确......
filter {
mutate {
# we use a "temporary" field with an arbitrary value
add_field => { "[@metadata][test_field_check]" => "a null value" }
}
mutate {
# we copy the field of interest into that field.
# If the field of interest doesn't exist, copy is not executed.
copy => { "testField" => "[@metadata][test_field_check]" }
}
# if testField didn't exist, our field will have the arbitrary value
if [@metadata][test_field_check] == "a null value" {
# logic to execute when [testField] did not exist
mutate { add_field => { "testField" => "" }}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.