【问题标题】:Correct syntax for document_id in Logstash Elasticsearch OutputLogstash Elasticsearch 输出中 document_id 的正确语法
【发布时间】:2020-09-15 13:02:57
【问题描述】:

所以我正在尝试使用 logstash 将数据从 MongoDB 移动到 elasticsearch。我不想重复写入,所以我在输出中使用doc_as_upsert => truedocument_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"
    }
}

使用字符串 %{datetime} 作为 ID,而不是 datetime 字段的值用作 _id。我该如何解决这个问题?

【问题讨论】:

    标签: mongodb elasticsearch jdbc logstash


    【解决方案1】:

    document_id 字段不在根级别,因此您需要将语法更改为:

    document_id => "%{[document][datetime}}"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-23
      • 2018-09-20
      • 1970-01-01
      相关资源
      最近更新 更多