Hi,
I want the "index" name to be my filename when uploading to elastic via Logtash, Searched widely but unable to get a working solution. Need help how we can use the grok to set the index name as per filename
I tried the below configs but not working
CONFIG: 1
Logtash.conf
input {
file {
path => "C:/logtash/*"
start_position => "beginning"
}
}
filter {
# Drop Elasticsearch Bulk API control lines
if ([message] =~ "{"index") {
drop {}
}
json {
source => "message"
remove_field => "message"
}
grok {
match => [
"source", "C:\\logtash\\%{DATA:myindex}.json"
]
}
}
output {
elasticsearch {
hosts => "localhost:9200"
document_type => "pcap_file"
manage_template => false
index => "%{[myindex]}"
}
}
CONFIG-2
input {
file {
path => "C:/logtash/*"
start_position => "beginning"
}
}
filter {
# Drop Elasticsearch Bulk API control lines
if ([message] =~ "{"index") {
drop {}
}
json {
source => "message"
remove_field => "message"
}
grok {
match => ["path","%{GREEDYDATA}/%{GREEDYDATA:filename}\.json"]
}
}
output {
elasticsearch {
hosts => "localhost:9200"
document_type => "pcap_file"
manage_template => false
index => filename
}
}