
Managing log data effectively is crucial for observability and analysis. While log shippers like Filebeat provide a robust way to collect and send data, controlling where that data lands in your Elasticsearch cluster is key to organization and performance. By default, Filebeat typically sends logs to time-based indices following a standard pattern, often incorporating the agent version. However, there are many scenarios where you need more granular control, directing specific logs to their own, dedicated indices.
This control is essential for several reasons. Custom indices allow you to logically separate different types of logs – for instance, system logs, application logs, security logs, or logs from different environments. This separation makes searching, filtering, and managing the data much easier. Furthermore, dedicated indices enable you to apply specific Index Lifecycle Management (ILM) policies, allowing for distinct retention periods, rollover strategies, and storage tiers tailored to the needs of each data type. Performance can also benefit from targeted queries against smaller, relevant indices instead of scanning across vast, general-purpose ones.
The process to achieve this involves modifying the Filebeat configuration file, typically named filebeat.yml
. Within this file, you define how Filebeat collects input and, importantly, where it sends the output. The critical section for directing logs to a specific Elasticsearch index is found under output.elasticsearch
.
To send all data processed by a particular Filebeat instance (or even specific inputs defined within it) to a custom index name, you need to add or modify the index
setting within the output.elasticsearch
block. For example, you could set index: "my-application-logs-%{+yyyy.MM.dd}"
. This setting tells Filebeat to use “my-application-logs-” followed by the current date in YYYY.MM.DD
format as the target index name for all events it outputs. The %{+format}
syntax is powerful, allowing dynamic naming based on timestamps.
It’s important to consider how index templates interact with your custom index names. While the index
setting tells Filebeat which index name to use, an index template tells Elasticsearch how to configure that index when it’s first created (e.g., mapping types, settings). Filebeat often handles the loading of default templates, but for custom index patterns like "my-application-logs-*"
or "my-system-logs-*"
that don’t match Filebeat’s standard patterns, you may need to ensure a suitable template exists in Elasticsearch that matches your chosen index name pattern. This template ensures your data has the correct field mappings.
By carefully configuring the index
setting in your Filebeat output configuration, you gain significant flexibility in organizing your log data within Elasticsearch, leading to improved manageability, performance, and compliance with data retention policies. Remember to restart the Filebeat service after making changes to your configuration file for the new settings to take effect. This targeted approach ensures your logs land exactly where you need them.
Source: https://kifarunix.com/configure-filebeat-8-to-write-logs-to-specific-index/