# ELK配置之，filebeat更改自定义索引名称

## ELK配置之，filebeat更改自定义索引名称

> filebeat客户端添加成功后，在kibana查看添加的索引，默认情况下，当索引生命周期管理（ILM）被禁用或不受支持时，Filebeat 使用时间序列索引。索引命名格式为 filebeat-7.16.1-yyyy.MM.dd。

* 一台filebeat还好，可以清楚的分辨，但当多台机器添加后，共用一个索引名，无法分辨，这时需要自定义索引名称。有两种方法更改索引名称。

#### 方法一：

* 在filebeat.yml文件中，配置setup.template.name和 setup.template.pattern选项以匹配新名称。

```bash
sudo vim /etc/filebeat/filebeat.yml
# 添加以下选项，这里将索引名称改为elk-file

output.elasticsearch.index: "elk-file-%{[agent.version]}-%{+yyyy.MM.dd}"
setup.template.name: "elk-file"
setup.template.pattern: "elk-file-*"
setup.ilm.enabled: false

# 重启filebeat，索引名称格式变成，elk-file-7.16.1-yyyy.MM.dd
```

> 注：从7.0版本开始，索引生命周期管理（ILM）默认是开启状态，当开启状态时候，setup.template.name和 setup.template.pattern两个参数不生效，所以还需要配置关闭ILM，即setup.ilm.enabled: false

> 官方参考文档：<https://www.elastic.co/guide/en/beats/filebeat/current/change-index-name.html>

#### 方法二：

```bash
# 索引生命周期管理（ILM）默认是开启状态，在不关闭ILM情况下更改索引名称。在配置文件filebeat.yml添加以下选项即可。

setup.ilm.enabled: auto
setup.ilm.rollover_alias: "elk-file"
setup.ilm.pattern: "{now/d}-000001"

# 重启后，索引名称为elk-file-yyyy.MM.dd-000001 格式。
```

> 官方参考文档：<https://www.elastic.co/guide/en/beats/filebeat/current/ilm.html>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://close.gitbook.io/yun-wei-bi-ji/es/elk-pei-zhi-zhi-filebeat-geng-gai-zi-ding-yi-suo-yin-ming-cheng.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
