0

这是select语句,它是一个事务数据,每次将数据插入UserProfile时,旧的索引值都会从弹性中删除

  jdbc {
    statement => "SELECT userId,salesTeam FROM UserProfile with (nolock)"
}
output {
    elasticsearch {
    hosts => ["localhost:9200"]
    index => "q_d"
    document_type => "cd"
    document_id => "%{userId}%"
  }
  stdout { codec => rubydebug }
}

如果有任何更改,我想更新现有文档,否则索引新文档。
我在这里做错了什么?

4

1 回答 1

1
input {
    jdbc {
        # Postgres jdbc connection string to our database, mydb
        jdbc_connection_string => "jdbc:postgresql://localhost:5432/bhavya"
        # The user we wish to execute our statement as
        jdbc_user => "postgres"
        # The path to our downloaded jdbc driver
        jdbc_driver_library => "/root/postgresql-42.2.2.jar"
        # The name of the driver class for Postgresql
        jdbc_driver_class => "org.postgresql.Driver"
        jdbc_password => "postgres"
        jdbc_validate_connection => true
        #You can schedule input from this plugin,the following uses cron syntax
        schedule => "* * * * *"
        # our query
        statement => "SELECT uid,email,first_name,last_name FROM contacts"
    }
}

output {
    elasticsearch {
    hosts => ["localhost:9200"]
    index => "contacts"
    document_type => "record"
    document_id => "%{uid}"
  }
  stdout { codec => rubydebug }
}

首先,您应该根据您的数据库添加我在输入插件中指定的上述选项。我使用 Postgresql 作为数据库。因此,您需要为该数据库下载相应的驱动程序库 jar 并指定与之对应的路径。

其次,您应该在“jdbc”插件中使用 schedule 选项,以便它定期从数据库中读取数据。

第三,您应该从“输出”插件部分的“document_id”部分中删除一个额外的“%”。

您应该参考此页面以将数据从数据库导入logstash:->

https://www.elastic.co/blog/logstash-jdbc-input-plugin

于 2018-07-01T04:58:59.813 回答