我有一个logstash 客户端和服务器。
客户端将带有logstash的udp输出的日志文件发送到服务器,服务器也运行logstash来获取这些日志。在服务器上,我有一个 json 过滤器,它会在实际日志的字段中提取 json 格式的消息,以便 elasticsearch 可以对它们进行索引。
这是我来自服务器的代码:
input{
udp{}
}
filter{
json {
source => "message"
}
}
output{
elasticsearch{
}
}
并来自客户:
input{
file{
type => "apache-access"
path => "/var/log/apache2/access.log"
}
}
output{
udp{
host => "192.168.0.3"
}
}
这段代码工作正常,除了一件事:
以某种方式我得到了这个领域type
两次,一次作为type
并一度作为_type
,它们具有相同的内容。
我尝试删除type
- 场与mutate
-像这样过滤:
mutate{
remove_field => [ "type" ]
}
但这个过滤器同时删除了type
字段。(_type
字段设置为默认值:logs)
我怎样才能保留_type
字段并删除type
field?
它以这种方式对我有用:
input {
file {
add_field => { "[@metadata][type]" => "apache-access" }
path => "/var/log/apache2/access.log"
}
}
filter {
......
if [@metadata][type] == "xxx" {
}
......
}
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "logstash-%{+YYYY.MM.dd}"
document_type => "%{[@metadata][type]}"
}
}
@元数据和文档类型
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)