logstash一共有 input,filter,output 三个模块
conf示例
input {
jdbc {
jdbc_connection_string => "jdbc:mysql:/XXX
jdbc_user => "XXX"
jdbc_password => "XXX"
jdbc_driver_library => "/data/logstash-7.1.1/logstash-core/lib/jars/mysql-connector-java-8.0.19.jar"
jdbc_driver_class => "com.mysql.cj.jdbc.Driver"
jdbc_paging_enabled => true
jdbc_page_size => "10000"
jdbc_default_timezone =>"Asia/Shanghai"
statement => "select XXX from user where id >=:sql_last_value limit 10000"
schedule => "*/5 * * * * *"
use_column_value => true
tracking_column => "id"
tracking_column_type => "numeric"
last_run_metadata_path => "/data/logstash-7.1.1/bin/prod/user_prod"
}
}
output {
elasticsearch {
hosts => ["XXX:9200"]
user => "XXX"
password => "XXX"
index => "XXX_index"
action => "update"
doc_as_upsert => "true"
document_id => "%{id}"
}
}
output插件配置
output {
elasticsearch {
hosts => ["XXX:9200"]
user => "XXX"
password => "XXX"
index => "XXX_index"
action => "update"
doc_as_upsert => "true"
document_id => "%{id}"
}
}
action类型
action对应文档看 Elasticsearch bulk API documentation
几种 output es 的 action 配置
output {
elasticsearch {
hosts => ["XXX:9200"]
user => "XXX"
password => "XXX"
index => "XXX_index"
action => "index"
document_id => "%{id}"
}
}
注意:
output {
elasticsearch {
hosts => ["XXX:9200"]
user => "XXX"
password => "XXX"
index => "XXX_index"
action => "delete"
document_id => "%{id}"
}
}
output {
elasticsearch {
hosts => ["XXX:9200"]
user => "XXX"
password => "XXX"
index => "XXX_index"
action => "update"
document_id => "%{id}"
}
}
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "logstash-%{+YYYY.MM.dd}"
document_id => "%{id}"
action => "update"
doc_as_upsert => true
# 不能同时设置 doc_as_upsert => ture 和 upsert
# upsert => '{"test":"hello world"}'
}
}
注意:
output {
elasticsearch {
scripted_upsert => "true"
script => "ctx._source.message = params.event.get('message')"
}
}
output {
elasticsearch {
hosts => ["XXX:9200"]
user => "XXX"
password => "XXX"
index => "XXX_index"
action => "create"
document_id => "%{id}"
manage_template => true
template => "/data/logstash-7.1.1/bin/temp/xxx.json"
template_overwrite => "true"
template_name => "test"
}
}
注意:
template_overwrite
设置为true,模板名字一样的时候,logstash的该模板(template_name
)会覆盖es中的该命名模板manage_template
打开/关闭模板管理,默认true若为false需要手动预加载模板到es预加载
curl -ss -XPUT "http://localhost:9200/_template/indexName/" -H 'Content-Type: application/json' -d @"/data/logstash-7.1.1/bin/temp/xxx.json";
template
给出模板的路径template_name
是在ES中保存模板的名称nohup sh logstash --path.data=XXX_test -f XXX.conf > XXX.out&