Logstash Elasticsearch 输出中 document_id 的正确语法
Correct syntax for document_id in Logstash Elasticsearch Output
所以我正在尝试使用 logstash 将数据从 MongoDB 移动到 elasticsearch。我不想重复写入,所以我在输出中使用 doc_as_upsert => true
和 document_id
参数。这是我的 logstash
配置文件
input {
jdbc{
jdbc_driver_class => "com.dbschema.MongoJdbcDriver"
jdbc_driver_library => "/path/to/mongojdbc1.8.jar"
jdbc_user => ""
jdbc_password => ""
jdbc_connection_string => "jdbc:mongodb://127.0.0.1:27017/db1"
statement => "db1.coll1.find({ },{'_id': false})"
}
}
output {
elasticsearch {
hosts => ["http://127.0.0.1:9200"]
index => "test"
user => ""
password => ""
doc_as_upsert => true
document_id => "%{datetime}"
}
}
如您所见,我正在尝试使用 MongoDB 文档(它是一个字符串)的 datetime 字段作为 elasticsearch 的文档 ID。但这是插入 Elasticsearch 的文档的样子:
{
"_index" : "test",
"_type" : "_doc",
"_id" : "%{datetime}",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2020-05-28T08:53:28.244Z",
"document" : {
# .. some fields ..
"datetime" : "2020-05-28 14:22:29.133363",
# .. some fields ..
},
"@version" : "1"
}
}
不是将日期时间字段的值用作 _id,而是将字符串 %{datetime} 用作 ID。我该如何解决这个问题?
document_id
字段不在根级别,因此您需要将语法更改为:
document_id => "%{[document][datetime}}"
所以我正在尝试使用 logstash 将数据从 MongoDB 移动到 elasticsearch。我不想重复写入,所以我在输出中使用 doc_as_upsert => true
和 document_id
参数。这是我的 logstash
input {
jdbc{
jdbc_driver_class => "com.dbschema.MongoJdbcDriver"
jdbc_driver_library => "/path/to/mongojdbc1.8.jar"
jdbc_user => ""
jdbc_password => ""
jdbc_connection_string => "jdbc:mongodb://127.0.0.1:27017/db1"
statement => "db1.coll1.find({ },{'_id': false})"
}
}
output {
elasticsearch {
hosts => ["http://127.0.0.1:9200"]
index => "test"
user => ""
password => ""
doc_as_upsert => true
document_id => "%{datetime}"
}
}
如您所见,我正在尝试使用 MongoDB 文档(它是一个字符串)的 datetime 字段作为 elasticsearch 的文档 ID。但这是插入 Elasticsearch 的文档的样子:
{
"_index" : "test",
"_type" : "_doc",
"_id" : "%{datetime}",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2020-05-28T08:53:28.244Z",
"document" : {
# .. some fields ..
"datetime" : "2020-05-28 14:22:29.133363",
# .. some fields ..
},
"@version" : "1"
}
}
不是将日期时间字段的值用作 _id,而是将字符串 %{datetime} 用作 ID。我该如何解决这个问题?
document_id
字段不在根级别,因此您需要将语法更改为:
document_id => "%{[document][datetime}}"