[关于添加字段的this文档,我看到filebeat可以按名称和值添加任何自定义字段,这些字段将附加到Filebeat推送到Elasticsearch的每个文档中。
这在filebeat.yml中定义:
processors:
- add_fields:
target: project
fields:
name: myproject
id: '574734885120952459'
是否有一种方法,严格来说是来自filebeat.yml,也可以给在此添加的字段指定“类型”?例如,我可以分配“名称”以键入“关键字”吗?
我见过的唯一不涉及filebeat.yml的方法,而是在filebeat目录中创建一个定制的fields.yml文件(这一切适用于任何拍子),并在“ beat”键下指定字段和类型。
例如,如果上面的字段“ id”在filebeat.yml中声明,并且我们希望它是类型为“关键字”的自定义字段,我们将执行以下操作:
将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,使用适合您的环境的任何方法将模板加载到弹性中。
(假定所有版本均为7.x)
编辑:
显然在filebeat.yml文件中设置“ setup.template.append_fields”选项也可以,但是我没有探索过。
https://www.elastic.co/guide/en/beats/filebeat/current/configuration-template.html