gpt4 book ai didi

elasticsearch - 使用Logstash句柄删除方案的增量索引

转载 作者:行者123 更新时间:2023-12-03 01:22:00 25 4
gpt4 key购买 nike

每当使用新的行插入或更新时,我都会使用Logstash配置在下面进行增量索引编制,我能够从MSSQL Server获得那些特定的行并将其作为文档插入Elasticsearch中,但是挑战在于删除操作。

Logstash配置文件

input {
jdbc {
jdbc_driver_library => ""
jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
jdbc_connection_string => "jdbc:sqlserver://xxxxx;databaseName=xxxx;"
jdbc_user => "xxxx"
jdbc_paging_enabled => true
tracking_column => modified_date
tracking_column_type => "timestamp"
use_column_value => true
jdbc_password => "xxxx"
clean_run => true
schedule => "*/1 * * * *"
statement => "Select * from [dbo].[xxxx] where modified_date >:sql_last_value"
}
}

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

output {
elasticsearch {
hosts => "xxxxx"
user => "xxxxx"
password => "xxxxx"
index => "xxxxx"
document_type => "_doc"
document_id => "%{id}"

}
stdout { codec => rubydebug }
}

如何使用Logstash使用增量索引方法删除MSSQL Server中已删除的文档。我不知道如何处理特别是删除操作。

有人可以建议如何实现这一目标吗?

最佳答案

大家好,我能够使用以下代码处理插入,更新和删除。这可能对某些尝试相同的人有所帮助

input {
jdbc {
jdbc_driver_library => ""
jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
jdbc_connection_string => "jdbc:sqlserver://xxxxx:1433;databaseName=xxxxx;"
jdbc_user => "xxxxx"
jdbc_paging_enabled => true
tracking_column => modified_date
tracking_column_type => "timestamp"
use_column_value => true
jdbc_password => "xxxxx"
clean_run => true
schedule => "*/1 * * * *"
statement => "Select * from [dbo].[xxxx] where modified_date >:sql_last_value"
}
}

filter {
if [is_deleted] {
mutate {
add_field => {
"[@metadata][elasticsearch_action]" => "delete"
}
}
mutate {
remove_field => [ "is_deleted","@version","@timestamp" ]
}
} else {
mutate {
add_field => {
"[@metadata][elasticsearch_action]" => "index"
}
}
mutate {
remove_field => [ "is_deleted","@version","@timestamp" ]
}
}
}

output {
elasticsearch {
hosts => "xxxxx"
user => "elastic"
password => "xxxxx"
index => "xxxxx"
action => "%{[@metadata][elasticsearch_action]}"
document_type => "_doc"
document_id => "%{id}"

}
stdout { codec => rubydebug }
}

尤其要感谢Claudio M

关于elasticsearch - 使用Logstash句柄删除方案的增量索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59854441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com