在 Filebeat 中,**索引名(index name)**通常是通过 Elasticsearch output 来定义的。下面按常见场景给你说明。
filebeat.yml 中直接定义索引名(最常见)output.elasticsearch:
hosts: ["http://localhost:9200"]
index: "filebeat-%{+yyyy.MM.dd}"
✅ 结果:
filebeat-2026.01.21
filebeat-2026.01.22
setup.template.name 和 setup.template.pattern如果你希望 索引模板和索引名保持一致,可以这样写:
setup.template.name: "filebeat"
setup.template.pattern: "filebeat-*"
output.elasticsearch:
hosts: ["http://localhost:9200"]
index: "filebeat-%{+yyyy.MM.dd}"
⚠️ 注意:
setup.template.pattern 只影响 模板匹配output.elasticsearch.indexoutput.elasticsearch:
hosts: ["http://localhost:9200"]
index: "filebeat-prod-%{+yyyy.MM.dd}"
或根据字段动态生成索引(高级用法):
output.elasticsearch:
hosts: ["http://localhost:9200"]
indices:
- index: "filebeat-app-%{+yyyy.MM.dd}"
when.contains:
fields:
type: "app"
- index: "filebeat-nginx-%{+yyyy.MM.dd}"
when.contains:
fields:
type: "nginx"
fields:
env: "test"
fields_under_root: true
output.elasticsearch:
hosts: ["http://localhost:9200"]
index: "filebeat-%{[env]}-%{+yyyy.MM.dd}"
✅ 结果:
filebeat-test-2026.01.21
如果你 自定义了 index,但发现不生效,很可能是 ILM(索引生命周期管理) 在起作用。
setup.ilm.enabled: false
或者在 Elastic Stack ≥ 7.x 中:
setup.ilm:
enabled: false
✅ 最简单的自定义索引方式
output.elasticsearch:
hosts: ["http://localhost:9200"]
index: "filebeat-%{+yyyy.MM.dd}"
setup.ilm.enabled: false
如果你愿意,可以告诉我:
我可以帮你写一份 完整可用的 filebeat.yml 示例。