查看有关添加字段的this文档,我发现filebeat可以按名称和值添加任何自定义字段,这些字段将附加到Filebeat推送到Elasticsearch的每个文档中。

这在filebeat.yml中定义:

processors:
- add_fields:
    target: project
    fields:
      name: myproject
      id: '574734885120952459'

是否有一种方法,严格来说来自filebeat.yml,也可以为此处添加的字段赋予“类型”?例如,可以分配“名称”以键入“关键字”吗?

最佳答案

我看到要完成的唯一方法不涉及filebeat.yml,而是在filebeat目录中创建一个自定义的fields.yml文件(这一切适用于任何拍子),并在“beat”键下指定字段和类型。

例如,如果在文件beat.yml中声明了上面的字段“id”,并且我们希望它是类型为“关键字”的自定义字段,则我们将执行以下操作:

将fields.yml复制到filebeat目录中的my_filebeat_fields.yml文件。
在my_filebeat_fields中,添加以下部分:

- key: beat
  anchor: beat-common
  title: Beat
  description: >
    Contains common beat fields available in all event types.
  fields:
    # your customization begins here:
    - name: id
    - type: keyword

然后执行以下操作以使用此新的自定义字段文件:

修改filebeat.yml的这一部分以包括:
#==================== Elasticsearch template setting ==========================

setup.template.name: "filebeat-*"
setup.template.fields: "my_filebeat_fields.yml"
setup.template.overwrite: true

然后按照this guide的要求,使用适合您环境的任何方法将模板加载到elastic中。

(假设所有版本均为7.x)

编辑:

显然,在filebeat.yml文件中设置“setup.template.append_fields”选项也可以工作,但是我没有对此进行探讨。

https://www.elastic.co/guide/en/beats/filebeat/current/configuration-template.html

关于elasticsearch - 使用filebeat.yml中的add_fields处理器定义字段类型?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60216687/

10-13 05:02