使用 Logstash 从 SQL 服务器到 Elasticsearch 的增量索引

Incremental indexing using Logstash from SQL Server to Elasticsearch

大家好我在 运行 我的 logstash 将记录从 SQLserver 数据库索引到 elasticsearch 时出现以下错误

Java Version : 13
Logstash : 7.2.0
Elastic search :  7.2.0
JDBC Driver :  mssql-jdbc-7.4.1.jre12-shaded

我的配置文件

input {
jdbc {
jdbc_driver_library => "C:\Users\Mohan\Downloads\MsoftDriver\sqljdbc_7.4\enu\mssql-jdbc-7.4.1.jre12-shaded.jar"
jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
jdbc_connection_string => "jdbc:sqlserver://DESKTOP-VHDBS6E\SQLEXPRESS:1433;databaseName=mohan;"
jdbc_user => "mohan"
jdbc_password => "mohan"
statement => "SELECT * FROM [User_Name]"
start_position=> "beginning"
}
}
filter {
}

output {
elasticsearch {
hosts => "http://localhost:9200"

index => "Employee"

}
stdout { codec => rubydebug }
}

低于错误

 Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Something is wrong with your configuration.", :backtrace=>["C:/Users/Mohan/Desktop/EsearchKibana/logstash-7.2.0/logstash-core/lib/logstash/config/mixin.rb:87:in `config_init'", "C:/Users/Mohan/Desktop/EsearchKibana/logstash-7.2.0/logstash-core/lib/logstash/inputs/base.rb:60:in `initialize'", "org/logstash/plugins/PluginFactoryExt.java:258:in `plugin'", "org/logstash/plugins/PluginFactoryExt.java:120:in `buildInput'", "org/logstash/execution/JavaBasePipelineExt.java:50:in `initialize'", "C:/Users/Mohan/Desktop/EsearchKibana/logstash-7.2.0/logstash-core/lib/logstash/java_pipeline.rb:24:in `initialize'", "C:/Users/Mohan/Desktop/EsearchKibana/logstash-7.2.0/logstash-core/lib/logstash/pipeline_action/create.rb:36:in `execute'", "C:/Users/Mohan/Desktop/EsearchKibana/logstash-7.2.0/logstash-core/lib/logstash/agent.rb:325:in `block in converge_state'"]}

谁能帮我解决这个问题?

嗯,jdbc-input 插件没有这样的设置 "start_position"。 Logstash 无法识别此设置,因此失败。看看 doc - 你不会在那里找到它。

此外,请注意 jdbc-input-plugin 中存在一个错误,在 Java 版本 9 之后(我猜这将是您的配置的下一个问题)。所以请参考这个github issue and this workaround当logstash因为无法加载jdbc驱动程序而失败时

错误是因为start_position=> "beginning"。请评论并尝试一次。

嗨,以上所有问题都已解决,我希望这是由于错误的 JDBC 驱动程序造成的。我直接从 link 下面下载了 JDBC 客户端而不是 Microsoft 并将文件放在

\logstash-7.2.0\logstash-core\lib\jars

https://www.elastic.co/downloads/past-releases/jdbc-client-7-2-0

注意:我的logstash版本是7.2.0

logstash 配置适用于增量索引方法

input {
jdbc {
jdbc_driver_library => ""
jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
jdbc_connection_string => "jdbc:sqlserver://DESKTOP-VHDBS6E\SQLEXPRESS:1433;databaseName=xxxxx;"
jdbc_user => "xxxxx"
jdbc_password => ""xxxx
jdbc_paging_enabled => true
tracking_column => modified_date
use_column_value => true
clean_run => true
tracking_column_type => "timestamp"
schedule => "*/2 * * * * *"
statement => "SELECT * from [User_Name] where modified_date >:sql_last_value"
}
}

filter {
 mutate {
   remove_field => ["@version","@timestamp"]
 }
}

output {
elasticsearch {
hosts => "http://localhost:9200"
index => "employee"
document_type => "_doc"
document_id => "%{id}"

}
stdout { codec => rubydebug }
}

我希望这篇文章对那些尝试使用 logstash 处理增量索引到 Elasticsearch 的人有所帮助