【发布时间】:2021-05-06 12:11:00
【问题描述】:
我正在尝试以更具可扩展性的方式编写此 .conf 文件,我的想法是,为了在 elasticsearch 中拥有多索引,拆分路径并获取最后一个位置以具有 csv 名称并将其设置为类型和弹性搜索中的索引。
import pandas as pd
import numpy as np
input {
file {
path => "/home/aitor2/RETO8/BIGDATA/df_suministro_activa.csv"
start_position => "beginning"
sincedb_path => "/dev/null"
}
file {
path => "/home/aitor2/RETO8/BIGDATA/df_activo_consumo.csv"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
path2 = path.split('/')[-1]
filter {
if [path] == "/home/aitor2/RETO8/BIGDATA/df_suministro_activa.csv"{
mutate { replace => { type => path2 } }
csv {
separator => ","
skip_header => "true"
autodetect_column_names => true
}
ruby {
code => "event.to_hash.each { |k, v|
if k.start_with?('Linea') and v.is_a?(String)
event.set(k, v.to_f)
end
}
"
}
}
else if [path] == "/home/aitor2/RETO8/BIGDATA/df_activo_consumo.csv"{
mutate { replace => { type => "apaches2" } }
csv {
separator => ","
skip_header => "true"
autodetect_column_names => true
}
ruby {
code => "event.to_hash.each { |k, v|
if k.start_with?('Smart') and v.is_a?(String)
event.set(k, v.to_f)
end
}
"
}
}
}
output {
elasticsearch {
hosts => "http://localhost:9200"
index => "%{type}_indexer"
}
stdout {codec => rubydebug}
}
我尝试用path2 = path.split('/')[-1] 来做,但我不确定这是否可行。
【问题讨论】:
标签: elasticsearch logstash logstash-grok logstash-configuration