使logstash为不同的索引添加不同的输入

khe*_*bie 10 elasticsearch logstash

我已经设置了logstash来使用嵌入式弹性系统.
我可以记录事件.
我的logstash conf看起来如此:https://gist.github.com/khebbie/42d72d212cf3727a03a0

现在我想添加另一个udp输入并将该输入索引到另一个索引中.

这有可能吗?我会这样做,使报告更容易,所以我可以在一个索引中有系统日志事件,在另一个索引中有业务日志事件.

Mag*_*äck 45

if根据例如消息类型或对索引选择有重要意义的消息字段,在输出节中使用条件.

input {
  udp {
    ...
    type => "foo"
  }
  file {
    ...
    type => "bar"
  }
}

output {
  if [type] == "foo" {
    elasticsearch {
      ...
      index => "foo-index"
    }
  } else {
    elasticsearch {
      ...
      index => "bar-index"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

或者,如果消息类型可以直接进入索引名称,则可以使用单个输出声明:

elasticsearch {
  ...
  index => "%{type}-index"
}
Run Code Online (Sandbox Code Playgroud)

  • type属性[不鼓励](https://www.elastic.co/blog/index-type-parent-child-join-now-future-in-elasticsearch#sthash.GPJLwX6q.dpbs),也获得了"如果您的源中已有类型字段(它不会覆盖),则应用.所以最好使用标签或add_field. (2认同)