Logstash删除类型并保持_type [英] Logstash delete type and keep _type

查看:986
本文介绍了Logstash删除类型并保持_type的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个logstash客户端和服务器。

客户端将logstiles的logstash发送到服务器,并且服务器还运行logstash来获取这些日志。在服务器上,我有一个json过滤器在实际日志的字段中拉出json格式的消息,以便弹性搜索可以对它们进行索引。

I have a logstash client and server.
The client sends logfiles with the udp output of logstash to the server and the server also runs logstash to get these logs. On the server, I have a json filter that pulls the json formatted message in the fields of the actual log, so that elasticsearch can index them.

这是我的代码服务器:

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 ,他们有相同的内容。

This code works fine except one thing:
In some way i get the field type twice, once as type and once as _type, they have the same content.

我试图删除使用 mutate -filter键入 -field,如下所示:

I've tried to delete the type-field with the mutate-filter like this:

mutate{
  remove_field => [ "type" ]
}

但此过滤器同时移除键入字段( _type 字段设置为默认值: logs

but this filter removes both type fields.(the _type field is set to default: logs)

如何保留 _type 字段并删除类型字段?

How can I keep the _type field and remove the 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]}"
    }
}

@metadata和document_type

@metadata and document_type

这篇关于Logstash删除类型并保持_type的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆