1
我是logstash的新手,並且我有作爲流動場景的需求。我有以下日誌格式。Logstash迭代內部對象並插入到數據庫
{"library":"xyz","locations":["location1":"abc","location2":"mno"]}
然後我需要使用以下格式將這些數據添加到數據庫。
- 「位置」: 「庫」(數據庫字段)
- 「ABC」: 「XYZ」
- 「MNO」: 「XYZ」
到目前爲止,我已經做了提取json並將記錄存入數據庫。但上面的情況我需要添加兩個條目到數據庫。我需要知道如何迭代位置,每個位置添加記錄到數據庫.documentation鏈接或簡單的例子就足夠了。
這是我的conf文件
input {
file {
path=> "filePath"
start_position => beginning
sincedb_path => "/dev/null"
}
}
filter {
grok{
match => { "message" => "%{GREEDYDATA:request}"}
}
json{
source => "request"
target => "parsedJson"
}
mutate {
add_field =>
"locations" => "%{[parsedJson][locations]}"
"library" => "%{[parsedJson][library]}"
}
remove_field => ["request", "message", "@version", "host", "parsedJson"]
}
}
output {
stdout {
codec => rubydebug
}
mongodb{
collection => "library"
database => "db"
uri => "mongodb://127.0.0.1:27017"
}
}
當你說數據庫,你的意思是彈性搜索的輸出嗎?你能編輯你的問題並將你的輸出配置添加到它嗎? – pandaadb
嗨@pandaadb我更新了配置文件。感謝您的評論。 – Sajithv
好的 - 所以我認爲這可能不可能以你想要的方式。輸出只獲得1個事件並提交該事件。如果你想讓它們分開,你需要(a)創建一個過濾器來分隔你的字段併產生新的事件(目前只能用自定義過濾器)或者(b)創建你自己的輸出插件(基於mongodb)那裏是正確的。 – pandaadb