2.加载ES索引模板.md

Elasticsearch使用索引模板来定义:

  • 控制数据流和备份索引行为的设置。这些设置包括用于在备份索引增长和老化时管理备份索引的生命周期策略。
  • 确定如何分析字段的映射。每个映射设置用于特定数据栏的Elasticsearch数据类型

filebeat自带了推荐的索引模板,保持filebeat.yml中的默认配置,则filebeat会在成功连接到ES后自动加载模板.

加载索引模板需要连接到Elasticsearch。如果输出不是Elasticsearch(或Elasticsearch Service),则必须手动加载模板。

此页面显示如何将默认模板加载行为更改为:

  • 加载自定义索引模板
  • 覆盖现有索引模板
  • 禁用自动索引模板加载
  • 手动加载索引模板

有关模板设置选项的完整列表,请参阅Elasticsearch索引模板

加载自定义索引模板

要加载您自己的索引模板,请设置以下选项:

setup.template.name: "your_template_name"
setup.template.fields: "path/to/fields.yml"

您可以为数据流和索引加载模板。

覆盖现有索引模板

要覆盖已加载到Elasticsearch中的模板,请设置:

setup.template.overwrite: true

不要为多个Fileball实例启用此选项。如果您同时启动多个实例,它可能会因模板更新请求过多而使您的Elasticsearch过载。

禁用自动索引模板加载

如果您使用Elasticsearch以外的输出并且需要手动加载模板,您可能需要禁用自动模板加载。要禁用自动模板加载,请设置:

setup.template.enabled: false

如果禁用自动模板加载,则必须手动加载索引模板。

手动加载索引模板

要手动加载索引模板,请运行setup命令。需要连接到Elasticsearch。如果启用了另一个输出,您需要暂时禁用该输出并使用-E选项启用Elasticsearch。此处的示例假定启用了Logstash输出。如果Elasticsearch输出已启用,您可以省略-E标志。

如果您要连接到secured Elasticsearch cluster,请确保已按照 Quick start: installation and configuration.中的说明配置凭据。

如果运行FileBeat的主机没有与Elasticsearch的直接连接,请参阅 Load the index template manually (alternate method)

加载模板命令:

./filebeat setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'
docker run docker.elastic.co/beats/filebeat:8.5.2 setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'

force Kibana to look at newest documents

如果您已经使用FileBeat将数据索引到Elasticsearch中,索引可能包含旧文档。加载索引模板后,您可以从filebeat-*中删除旧文档,以 force Kibana to look at the newest documents.。

curl -XDELETE 'http://localhost:9200/filebeat-*'

此命令删除与模式filebeat匹配的所有索引。在运行此命令之前,请确保要删除与模式匹配的所有索引。

手动加载索引模板(替代方法)

如果运行FileBeat的主机没有与Elasticsearch的直接连接,您可以将索引模板导出到文件中,将其移动到具有连接的机器上,然后手动安装模板。

导出索引模板:

./filebeat export template > filebeat.template.json

安装模板:

curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/_index_template/filebeat-8.5.2 -d@filebeat.template.json

加载索引模板后,也加载数据流。如果不加载它,则必须授予发布者用户对filebed-8.5.2索引的manage权限。

curl -XPUT http://localhost:9200/_data_stream/filebeat-8.5.2

2.加载ES索引模板.md
http://blog.lujinkai.cn/运维/ELK/filebeats/How to guides/2.加载ES索引模板/
作者
像方便面一样的男子
发布于
2023年12月5日
许可协议