Reputation: 1169
I am using Logstash to replcate a database from MongoDB to Elasticsearch using Logstash 6.0.0, here is my config file:
input{
jdbc{
jdbc_driver_library => "/usr/share/logstash/driver/mongodb-driver-3.6.1.jar"
jdbc_driver_class => "mongodb.jdbc.MongoDriver"
jdbc_connection_string => "jdbc:mongodb://mongo:27017/DevDb"
jdbc_user => ""
statement => "*"
}
}
output {
elasticsearch {
hosts => 'http://user:xxxx@elasticsearch:9200'
index => 'mongo'
}
stdout { codec => rubydebug }
}
I am using the official MongoDB java driver, downloaded from this link: Mongo java driver, but I'm getting the following error:
Error: mongodb.jdbc.MongoDriver not loaded. Are you sure you've included the correct jdbc driver in :jdbc_driver_library?
Exception: LogStash::ConfigurationError
So what class name should I use?
Upvotes: 1
Views: 3917
Reputation: 315
input {
jdbc {
jdbc_driver_library => "mongojdbc1.3.jar"
jdbc_driver_class => "com.dbschema.MongoJdbcDriver"
jdbc_connection_string => "jdbc:mongodb://username:password@mongourl:27017/database_name?authSource=admin"
jdbc_user => ""
jdbc_password => ""
schedule => "* * * * * *"
statement => "db.collection_name.find({},{'_id': false});"
}
}
output {
elasticsearch {
hosts => ["http://elasticsearch:9200"]
index => "vm_server_%{+YYYY.MM.dd}"
user => "elastic"
password => "changeme"
}
}
This config worked for me and the driver that you have in the config file does not look like the jdbc driver. So look for the jdbc jar. https://bitbucket.org/dbschema/mongodb-jdbc-driver/src/master/
And if you are querying from mongo your json format might not look the same as it is in mongo. For that you can check the link https://discuss.elastic.co/t/issue-using-logstash-input-jdbc-to-load-mongo-data/174914
Upvotes: 3