Logstash SQL Server Data Import

Vivek Gupta picture Vivek Gupta · Jul 28, 2015 · Viewed 24.8k times · Source

I want to import data in ElasticSearch using Logstash using JDBC SQL Server as input but I am getting error class path is not correct.

Anybody know how to connect using Logstash for correct location for sqljdbc FILE WITH CONFIG FILE

Answer

user657527 picture user657527 · Aug 7, 2015

I think that path to the "sqljdbc4.jar" file is not correct. Here is the config I am using to query data from a sql db into elasticsearch (logstash.conf):

input {
  jdbc {
    jdbc_driver_library => "D:\temp\sqljdbc\sqljdbc_4.2\enu\sqljdbc42.jar"
    jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    jdbc_connection_string => "jdbc:sqlserver://DBSVR_NAME;user=****;password=****;"
    jdbc_user => "****"
    jdbc_password => "****"
    statement => "SELECT *
FROM [DB].[SCHEMA].[TABLE]"
  }
}
filter {
}
output {
  elasticsearch {
    hosts => "localhost"
    index => "INDEX_NAME"
    document_type => "DOCUMENT_TYPE"
    document_id => "%{id}"
    protocol => "http"
  }
  stdout { codec => rubydebug }
}

I downloaded the Microsoft JDBC Driver for SQL Server from here: "https://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx"

Extracted the files to the path specified in "jdbc_driver_library"

Then I ran the plugin command: "plugin install logstash-input-jdbc" to install the logstash input jdbc plugin.

And finally running logstash: "logstash -f logstash.conf".

As an aside: I am also using Elasticsearch.Net in a .Net service app to refresh the data "http://nest.azurewebsites.net/"

And this vid: "Adding Elasticsearch To An Existing .NET / SQL Server Application" "https://www.youtube.com/watch?v=sv-MflnT9qI" discuses using a Service Broker queue to get the data out of sql. We are currently exploring this as an option.

Edit - Updated host to hosts as in documentation here https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-hosts