全量:
驱动路径:驱动
input {
jdbc {
jdbc_driver_class => "com.dbschema.MongoJdbcDriver"
# jar包的目录
jdbc_driver_library => "../lib/jar/mongojdbc3.1.jar"
# mongo数据库对应的uri
jdbc_connection_string => "jdbc:mongodb://127.0.0.1:27017/aptshd"
# 这个不填
jdbc_user => ""
# 这个不填
jdbc_password => ""
# 表示每分钟中执行一次,以实现实时同步的效果
schedule => "* * * * *"
# mongodb的查询语句
statement => "db.busArrLeave.find({}, {_id: 0})"
}
}
output {
elasticsearch {
# es所在的地址
hosts => "localhost:9200"
# 导入到es上对应的索引
index => "test"
# 指定标识每条数据的字段
#document_id => "%{id}"
}
stdout {
codec => json_lines
}
}
增量:
input {
jdbc {
jdbc_driver_class => "com.dbschema.MongoJdbcDriver"
jdbc_default_timezone =>"Asia/Shanghai"
# jar包的目录
jdbc_driver_library => "../lib/jars/mongojdbc3.1.jar"
# mongo数据库对应的uri
jdbc_connection_string => "jdbc:mongodb://127.0.0.1:27017/aptshd"
# 这个不填
jdbc_user => ""
# 这个不填
jdbc_password => ""
# 表示每分钟中执行一次,以实现实时同步的效果
schedule => "* * * * *"
# 实现增量同步的mongodb的查询语句
statement => "db.busArrLeave.find({ActDateTime:{$gte:new Date(:sql_last_value)}},{_id:0}).sort({ActDateTime:-1})"
#statement => "db.test.find({},{_id:0}).sort({ActDateTime:-1})"
# 保存上一次执行时间的文件
last_run_metadata_path => "../config/mylast.txt"
#clean_run=>flase
}
}
filter
{
mutate
{
add_field => { "@content" => "%{document}" } #先新建一个新的字段,并将friends赋值给它
}
json
{
source => "@content" #再进行解析
remove_field => [ "@timestamp","@version","@content","document","_class" ] #删除不必要的字段,也可以不用这语句
}
}
注意:sql_last_value 时区问题
#filter {
#mutate {
# Renames the 'HOSTORIP' field to 'client_ip'
#rename => { "id" => "uid" }
#}
#}
output {
elasticsearch {
# es所在的地址
hosts => "192.168.1.3:9200"
# 导入到es上对应的索引
index => "bus_arr_leave"
#index => "test"
# 指定标识每条数据的字段
#document_id => "%{id}"
}
stdout {
codec => json_lines
}
}