简体   繁体   中英

Logstash filename as ElasticSearch index

I am using a folder as input:

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

and as output:

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

I want the index in elasticsearch to be the name of the file being indexed. I've tried variations of this answer with no success as I am not clear on what it is doing: https://stackoverflow.com/a/40156466/6483906

You'll need to use a grok filter to find the last portion of the filename:

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

and then just use the portion in your index name index => "%{index_name}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM