Filebeat、Kafka - 按 %{[type]} 或常量值命名的主题?

Filebeat, Kafka - topic name by %{[type]} or constant value?

我有filebeat,输出到kafka。
根据文档的 type,我需要将日志发送到不同的主题。

在伪代码中:

if(type == type1)
topic = 'special.type1.topic'
...
else
topic = '%{[type]}'

我发现这是可能的:

topics:
      - topic: 'special.type1.topic'
        when: 
          equals:
            %{[type]}: type1

但是如果 type 是被测试的 none,我想使用默认的主题名称,如 else 语句中所见。这可能吗?

为所有未测试的文件提供默认主题字段。当 none 的规则匹配 "topics" 时,将使用主题字段。

在这种情况下,您不需要 "topics" 中的任何其他规则。您的配置将如下所示:

   topic: untested-files
   topics:
      - topic: 'special.type1.topic'
        when: 
          equals:
            %{[type]}: type1