Yes, it is possible. Use gsub to extract folder name, then add in [@metadata][dir]
The best is to provide with dir name samples.
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "indexname_%{[@metadata][dir]}"
}
}
Other possibly is to set with IFs which is more strict and more usable in some cases.
output {
if ([@metadata][dir]=="dir1"){
elasticsearch {
hosts => ["http://localhost:9200"]
index => "indexname_%{[@metadata][dir]}"
}
}
else if ([@metadata][dir]=="dir2"){
elasticsearch {
hosts => ["http://localhost:9200"]
index => "indexname_%{[@metadata][dir]}"
}
}
else if ([@metadata][dir]=="dir3"){
elasticsearch {
hosts => ["http://localhost:9200"]
index => "indexname_%{[@metadata][dir]}"
}
}