I am using filebeat to collect some logs.
I have set the value of tags for each log, and I want to use that value as the name of the index.
Is that possible?
With the following method, it will be "[tags][0]-2021.07.28" instead of the value of tags.
(Actually, we want it to be "A-2021.07.28", "B-2021.07.28", etc.)
vi /etc/logstash/logstash-sample.config
... snip ...
output {
elasticsearch {
hosts => ["localhost"]
index => "%{[tags][0]}-%{+YYYY.MM.dd}"
}
... snip ...
As a workaround for now, I'm using if-else statements, but I'm having trouble with the increasing number of log types.
vi /etc/logstash/logstash-sample.config
... snip ...
if ( "A" in [tags][0] ) [
output {
elasticsearch {
hosts => ["localhost"]
index => "A-%{+YYYY.MM.dd}"
}
}
else if ( "B" in [tags][0] ) [
output {
elasticsearch {
hosts => ["localhost"]
index => "B-%{+YYYY.MM.dd}"
}
}
... snip ...
Do you have any good ideas?
Also, I'd really like to concatenate the values I set for tags (different lengths for different logs) into the name of the index.
(For example, I want to use "A-foo-bar-2021.07.28" or "B-hoge-2021.07.28.")
If that happens then the field [fields][index_name] does not exist. Double check your input by outputting to stdout and make sure that you define a field name. If you want you can also include an if statement before the output to set a default index name
Check out this example:
output {
if [fields][index_name] {
elasticsearch {
index => "%{[fields][index_name]}-%{+YYYY.MM.dd}"
}
} else {
elasticsearch {
index => "defaultindex-%{+YYYY.MM.dd}"
}
}
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.