[英]How to use Logstash split with field
我在文件data.json
存储了以下数据:
{"result":[{"number":"1"},{"number":"2"}]}
这是我的 logstash conf 文件:
input {
file {
path => "C:/work/apps/ELK/data.json"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter {
split {
field => "result"
}
}
output {
elasticsearch {
hosts => "localhost:9200"
index => "so"
document_type => 1
}
stdout { codec => rubydebug }
}
当我使用这个配置和它上面的数据运行 Logstash 时,我在 Elastic 中只有一个条目和整个文本(见下图)。
例如,当我修改数据以添加新行时:
"result":[
{"number":"1"},
{"number":"2"}]
result
仍然被忽略,但这次我确实有分裂,根据新行。 我在数据库中收到三条消息:
我使用原始 json 文件尝试了此处提出的解决方案,但同样没有解析任何内容(如第一种情况)。 我不明白为什么。
拆分过滤器不起作用,因为字段结果不存在。 要创建它,您需要解析您从文件中读取的 json,这将创建字段。
要解析 json,请在输入中使用json 编解码器或json filter 。
仅供参考,使用的最终配置:
input {
file {
path => "C:/work/apps/ELK/data.json"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter {
json {
source => "message"
remove_field => ["message", "host", "path"]
}
split {
field => "result"
add_field => {
"number" => "%{[result][number]}"
}
remove_field => "result"
}
}
output {
elasticsearch {
hosts => "localhost:9200"
index => "so"
document_type => 1
}
stdout { codec => rubydebug }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.