如何在输出中使用 mutate 过滤器插件

How to use mutate filter plugin in output

我有一个 logstash 配置。使用该配置,logstash 在过滤器中执行一些操作并发送输出。一切正常。

我想在同一配置文件中多一个 elasticsearch 输出。我的意思是在解析日志后,logstash 在删除一些字段并将它们发送到另一个索引之后,将结果发送到一个索引。我的目标是在下面的例子中。

output {
 elasticsearch {
      ..index1..
 }
 mutate {
   remove_field ...
} 
mutate {
   add_field ..
}
elasticsearch {
  ... index2 ...
}

}

但是我不能在输出中使用 mutate 插件?我怎样才能做到这一点?

感谢您的回答

mutate 是一个 filter 插件,因此它只能在 filter 块内工作。

您可以做的可能是使用 clone 过滤器复制您的事件,对原始事件和克隆事件应用不同的过滤器,然后相应地将两个副本传送到不同的输出。

大概看起来像这样

filter {
  clone {
    clones => ["cloned"]
  }
  # apply here filters that should be applied to both the primary and secondary event
  if [type] == "cloned" {
    # apply here filters that should be applied to the secondary event
  }
}

output {
  if [type] == "cloned" {
    elasticsearch {
      ... index2 ...
    }
  } else {
    elasticsearch {
      ... index1 ...
    }
  }
}

https://discuss.elastic.co/t/can-i-filter-the-output-data-separately/36064/5