从filebeat配置中的字段值创建索引名称



这是我的filebeat。yml文件:

filebeat.config:
modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
processors:
- add_cloud_metadata: ~
- add_docker_metadata: ~
- add_kubernetes_metadata: ~
output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
username: '${ELASTICSEARCH_USERNAME:}'
password: '${ELASTICSEARCH_PASSWORD:}'
setup.kibana:
host: '${KIBANA_HOST}'
ssl.enabled: false
filebeat.modules:
- module: kibana
- module: elasticsearch
fields_under_root: true
json.keys_under_root: true
filebeat.inputs:
- type: log
enabled: true
fields:
my_type: 'inventory'
index: 'test-%{[fields.my_type]}-%{+yyyy.MM.dd}'
paths:
- /var/log/kibana/kibana.log
setup.ilm.overwrite: true
setup.ilm.enabled: false
setup.template.name: 'test-%{[fields.my_type]}-%{+yyyy.MM.dd}'
setup.template.pattern: 'test-%{[fields.my_type]}-*'

我想从我的字段值创建索引名称(特别是日志文件名)当我尝试使用代理字段(如

)时,它可以工作
%{[agent.version]}

但是当我试图从我的自定义字段或其他可用的名称得到错误

%{[file.name]} or %{[fields.my_type]}

这是filebeat日志中的错误:

ERROR [publisher] pipeline/client.go:106 Failed to publish event: key not found

谢谢你的提示

根据你发布的内容,看起来你的index声明在错误的地方,因为它在输入而不是输出

https://www.elastic.co/guide/en/beats/filebeat/current/elasticsearch-output.html#index-option-es描述了您想要做的事情,但是试试这个;

output.elasticsearch:
hosts: ["http://eshost:9200"]
index: "%{[fields.my_type]}-%{[agent.version]}-%{+yyyy.MM.dd}" 

并从输入

中删除它