小编典典

使logstash将不同的输入添加到不同的索引

elasticsearch

我设置了logstash以使用嵌入式elastisearch。
我可以记录事件。 我的logstashconf看起来是这样的:https://gist.github.com/khebbie/42d72d212cf3727a03a0

现在,我想添加另一个udp输入,并在另一个索引中对该输入进行索引。

有可能吗?我这样做是为了使报告更加容易,因此我可以在一个索引中包含系统日志事件,而在另一个索引中包含业务日志事件。


阅读 676

收藏
2020-06-22

共1个答案

小编典典

if在输出部分中使用条件,例如,基于消息类型或对选择索引有意义的任何消息字段。

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

output {
  if [type] == "foo" {
    elasticsearch {
      ...
      index => "foo-index"
    }
  } else {
    elasticsearch {
      ...
      index => "bar-index"
    }
  }
}

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

elasticsearch {
  ...
  index => "%{type}-index"
}
2020-06-22