Elastic 只保留来自 logstash 的最后一条记录
Elastic is retaining only last record from logstash
这里是select语句,是一个交易数据,每次数据插入UserProfile时,elastic
会删除旧的索引值
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 }
}
如果有任何更改,我想更新现有文档,否则索引新文档。
我在这里做错了什么?
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 选项,以便它定期从数据库中读取数据。
第三,您应该从 "output" 插件部分的 "document_id" 部分删除一个额外的“%”。
您应该参考此页面以将数据从数据库导入 logstash:->
这里是select语句,是一个交易数据,每次数据插入UserProfile时,elastic
会删除旧的索引值 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 }
}
如果有任何更改,我想更新现有文档,否则索引新文档。
我在这里做错了什么?
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 选项,以便它定期从数据库中读取数据。
第三,您应该从 "output" 插件部分的 "document_id" 部分删除一个额外的“%”。
您应该参考此页面以将数据从数据库导入 logstash:->