首页 > 解决方案 > Logstash 文件名作为 ElasticSearch 索引

问题描述

我使用文件夹作为输入:

input {
  file {
    path => "C:/ProjectName/Uploads/*"
    start_position => "beginning"
    sincedb_path => "dev/null"
  }
}

并作为输出:

output {
  elasticsearch {
    hosts => "localhost"
    index => "manual_index_name" # want filename here
    document_type => "_doc"
  }     
}

我希望 elasticsearch 中的索引是被索引的文件的名称。我尝试了这个答案的变体但没有成功,因为我不清楚它在做什么:https ://stackoverflow.com/a/40156466/6483906

标签: elasticsearchlogstash

解决方案


您需要使用grok过滤器来查找文件名的最后一部分:

filter {
  grok {
     match => ["path", "Uploads/%{GREEDYDATA:index_name}" ]
  }
}

然后只需使用索引名称中的部分index => "%{index_name}"


推荐阅读