Hi Badger,
thank you very much again!
Your great explanation makes it a lot more clear.
I am getting the code is mostly working.
There seems to be only a minor issue.
input {
file {
path => "/home/estest/csv-data/Einwohner_test.csv"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter {
csv {
separator => ";"
skip_header => "true"
columns => ["LandID","LandName","RegionID","RegionName","2019","2020","2025","2030"]
}
ruby {
code => '
a = []
[ "2019", "2020", "2025", "2030" ].each { |x|
a << { "year" => x, "residents" => event.get(x) }
}
event.set("a", a)
'
}
split { field => "a" }
mutate { rename => { "[a][residents]" => "residents" "[a][year]" => "year" }
remove_field => [ "a" ]
convert => {residents => "integer" year => "integer"}
}
}
output {
elasticsearch {
hosts => "http://localhost:9200"
index => "demo-db-split"
}
stdout {}
}
As you can see for each entry the year and residents pair is correct but the other years are not getting dropped. Do I have to use some sort of conditional drop like
if field 20* then drop?
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jruby.ext.openssl.SecurityHelper (file:/tmp/jruby-2121/jruby9617472003062199941jopenssl.jar) to field java.security.MessageDigest.provider
WARNING: Please consider reporting this to the maintainers of org.jruby.ext.openssl.SecurityHelper
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults
Could not find log4j2 configuration at path /usr/share/logstash/config/log4j2.properties. Using default config which logs errors to the console
[INFO ] 2021-01-05 09:23:02.695 [main] runner - Starting Logstash {"logstash.version"=>"7.10.1", "jruby.version"=>"jruby 9.2.13.0 (2.5.7) 2020-08-03 9a89c94bcc OpenJDK 64-Bit Server VM 11.0.8+10 on 11.0.8+10 +indy +jit [linux-x86_64]"}
[WARN ] 2021-01-05 09:23:03.550 [LogStash::Runner] multilocal - Ignoring the 'pipelines.yml' file because modules or command line options are specified
[INFO ] 2021-01-05 09:23:11.230 [Converge PipelineAction::Create<main>] Reflections - Reflections took 163 ms to scan 1 urls, producing 23 keys and 47 values
[WARN ] 2021-01-05 09:23:12.603 [Converge PipelineAction::Create<main>] elasticsearch - Relying on default value of `pipeline.ecs_compatibility`, which may change in a future major release of Logstash. To avoid unexpected changes when upgrading Logstash, please explicitly declare your desired ECS Compatibility mode.
[INFO ] 2021-01-05 09:23:13.920 [[main]-pipeline-manager] elasticsearch - Elasticsearch pool URLs updated {:changes=>{:removed=>[], :added=>[http://localhost:9200/]}}
[WARN ] 2021-01-05 09:23:14.350 [[main]-pipeline-manager] elasticsearch - Restored connection to ES instance {:url=>"http://localhost:9200/"}
[INFO ] 2021-01-05 09:23:14.699 [[main]-pipeline-manager] elasticsearch - ES Output version determined {:es_version=>7}
[WARN ] 2021-01-05 09:23:14.701 [[main]-pipeline-manager] elasticsearch - Detected a 6.x and above cluster: the `type` event field won't be used to determine the document _type {:es_version=>7}
[INFO ] 2021-01-05 09:23:14.818 [[main]-pipeline-manager] elasticsearch - New Elasticsearch output {:class=>"LogStash::Outputs::ElasticSearch", :hosts=>["http://localhost:9200"]}
[INFO ] 2021-01-05 09:23:14.975 [Ruby-0-Thread-5: :1] elasticsearch - Using a default mapping template {:es_version=>7, :ecs_compatibility=>:disabled}
[INFO ] 2021-01-05 09:23:15.121 [Ruby-0-Thread-5: :1] elasticsearch - Attempting to install template {:manage_template=>{"index_patterns"=>"logstash-*", "version"=>60001, "settings"=>{"index.refresh_interval"=>"5s", "number_of_shards"=>1}, "mappings"=>{"dynamic_templates"=>[{"message_field"=>{"path_match"=>"message", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false}}}, {"string_fields"=>{"match"=>"*", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false, "fields"=>{"keyword"=>{"type"=>"keyword", "ignore_above"=>256}}}}}], "properties"=>{"@timestamp"=>{"type"=>"date"}, "@version"=>{"type"=>"keyword"}, "geoip"=>{"dynamic"=>true, "properties"=>{"ip"=>{"type"=>"ip"}, "location"=>{"type"=>"geo_point"}, "latitude"=>{"type"=>"half_float"}, "longitude"=>{"type"=>"half_float"}}}}}}}
[INFO ] 2021-01-05 09:23:15.137 [[main]-pipeline-manager] javapipeline - Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>1, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50, "pipeline.max_inflight"=>125, "pipeline.sources"=>["/etc/logstash/conf.d/pop-gr-split.conf"], :thread=>"#<Thread:0x72642c00 run>"}
[INFO ] 2021-01-05 09:23:17.435 [[main]-pipeline-manager] javapipeline - Pipeline Java execution initialization time {"seconds"=>2.29}
[INFO ] 2021-01-05 09:23:18.030 [[main]-pipeline-manager] javapipeline - Pipeline started {"pipeline.id"=>"main"}
[INFO ] 2021-01-05 09:23:18.131 [Agent thread] agent - Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[INFO ] 2021-01-05 09:23:18.200 [[main]<file] observingtail - START, creating Discoverer, Watch with file and sincedb collections
[INFO ] 2021-01-05 09:23:18.771 [Api Webserver] agent - Successfully started Logstash API endpoint {:port=>9600}
[WARN ] 2021-01-05 09:23:19.533 [[main]<file] plain - Received an event that has a different character encoding than you configured. {:text=>"1;Griechenland;12;S\\xFCd-Aegean Meer;344027;343127;337149;330509\\r", :expected_charset=>"UTF-8"}
{
"year" => 2019,
"RegionID" => "0",
"LandID" => "1",
"RegionName" => "Total",
"2020" => "10696536",
"message" => "1;Griechenland;0;Total;9006022;10696536;10510196;10303199\r",
"@version" => "1",
"2030" => "10303199",
"path" => "/home/estest/csv-data/Einwohner_test.csv",
"2019" => "9006022",
"2025" => "10510196",
"host" => "es1",
"@timestamp" => 2021-01-05T09:23:19.498Z,
"LandName" => "Griechenland",
"residents" => 9006022
}
{
"year" => 2020,
"RegionID" => "0",
"LandID" => "1",
"RegionName" => "Total",
"2020" => "10696536",
"message" => "1;Griechenland;0;Total;9006022;10696536;10510196;10303199\r",
"@version" => "1",
"2030" => "10303199",
"path" => "/home/estest/csv-data/Einwohner_test.csv",
"2019" => "9006022",
"2025" => "10510196",
"host" => "es1",
"@timestamp" => 2021-01-05T09:23:19.498Z,
"LandName" => "Griechenland",
"residents" => 10696536
}
Best regards
Tim