每个索引的 Filebeat 处理器脚本

Filebeat processor script per index

如何指定 Filebeat 处理器脚本应应用于哪个弹性索引? 我说的是这个处理器脚本 https://www.elastic.co/guide/en/beats/filebeat/current/processor-script.html 但我没有在任何地方看到指定索引的选项。

我有索引“防火墙”和“交换机”,我只想将脚本 A 应用于发送到“防火墙”索引的邮件,将脚本 B 仅应用于发送到“交换机”索引的邮件。 到目前为止,我只设法将脚本应用于所有消息(全局),但这意味着它也将脚本 A 应用于“切换”,我不希望这样。

将脚本应用于所有索引与将脚本应用于特定索引(如果可能)是否也会对性能产生影响?

编辑 在尝试了 Val 的解决方案之后,我得出了这个结论:

processors:
  - script:
      when:
        equals:
          _index: "firewall-11.2021"
      lang: javascript
      id: my_filter1
      file: ${path.config}/Script_A.js

消息中的 _index 字段正好是“firewall-11.2021”,因此对于具有 _index =“firewall-11.2021”的消息(也就是发送到“firewall-11.2021”的消息),它应该 运行 script_A指数)但它没有。如果我删除条件,Script_A 运行s 但对于所有消息。

这是我放置条件的 _index 字段:

您可以 define conditions 给定的处理器是否应该 运行。所以在你的情况下,它看起来像这样:

processors:
  - script:
      when:
        equals:
          _index: 'firewall'
      id: script_A
  - script:
      when:
        equals:
          _index: 'switch'
      id: script_B