[英]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.