How to upload csv file in elasticsearch using logstash?

668 views Asked by At

this is my logstash.conf file data

   input {
  file {
    path => "/home/niteshb/*.csv"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}                

filter {
  csv {
    separator => ","
    columns => ["tenant_id","hierarchy_name","attribute_name","item_pk"]
  }
}                

output {
  elasticsearch {
    hosts  => "http://localhost:9200"
    index  => "plan_record"
  }
  stdout {}
}

and to run it I am using

bin/logstash -f logstash.conf

After running it runs into exception and the exception is

  ] Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Expected one of [A-Za-z0-9_-], [ \\t\\r\\n], \"#\", \"=>\" at line 9, column 6 (byte 138) after input {\n  file {\n    path => \"/home/niteshb/*.csv\"\n    start_position => \"beginning\"\n    sincedb_path => \"dev/NULL\"\n  }\n\n  filter {\n  csv", :backtrace=>["/home/niteshb/Music/logstash-7.12.0/logstash-core/lib/logstash/compiler.rb:32:in `compile_imperative'", "org/logstash/execution/AbstractPipelineExt.java:184:in `initialize'", "org/logstash/execution/JavaBasePipelineExt.java:69:in `initialize'", "/home/niteshb/Music/logstash-7.12.0/logstash-core/lib/logstash/java_pipeline.rb:47:in `initialize'", "/home/niteshb/Music/logstash-7.12.0/logstash-core/lib/logstash/pipeline_action/create.rb:52:in `execute'", "/home/niteshb/Music/logstash-7.12.0/logstash-core/lib/logstash/agent.rb:389:in `block in converge_state'"]}
[2021-04-26T18:15:40,601][INFO ][logstash.runner          ] Logstash shut down.
[2021-04-26T18:15:40,611][FATAL][org.logstash.Logstash    ] Logstash stopped processing because of an error: (SystemExit) exit
org.jruby.exceptions.SystemExit: (SystemExit) exit

can someone please help me with this issue I am using linux system and I dont know whats going wrong ?

1

There are 1 answers

3
Val On

It always helps to properly format your configuration files. You're simply missing an closing curly brace at the end of the input and filter sections:

input {
  file {
    path => "/home/niteshb/*.csv"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}                  <--- add this

filter {
  csv {
    separator => ","
    columns => ["tenant_id","hierarchy_name","attribute_name","item_pk"]
  }
}                  <--- add this

output {
  elasticsearch {
    hosts  => "http://localhost:9200"
    index  => "plan_record"
  }
  stdout {}
}