Logstash couchdb_changes 没有正确地将文档删除传播到 Elasticsearch

Logstash couchdb_changes doesn't correctly propagate document deletion to Elasticsearch

我正在尝试使用 couchdb_changes Logstash 插件来检测我的 CouchDB 更改并充分更新 Elasticsearch 索引。

文档 creations/updates 工作正常,但不知何故删除不起作用。

这是我的 Logstash 配置:

input {
  couchdb_changes {
    host => "localhost"
    db   => "products"
    sequence_path => ".couchdb_products_seq"
    type => "product"
    tags => ["product"]
    keep_revision => true
  }
}

output {
  elasticsearch { 
    hosts => ["localhost:9200"]
    index => "products"
    # Pass the CouchDB document ID to Elastic, otherwise it is lost and Elastic generates a new one
    document_id => "%{[@metadata][_id]}"
  }
  # Debug
  stdout { 
    codec => rubydebug {
      metadata => true
    } 
  }
}

我遇到了 this link but the "protocol" parameter no longer exists in the elasticsearch Logstash 插件,我希望现在能修复这么大的错误。

在我的 Logstash 控制台中,我在删除 CouchDB 文档(来自 Futon)时看到了这个:

{
      "@version" => "1",
    "@timestamp" => "2016-05-13T14:06:55.734Z",
          "type" => "product",
          "tags" => [
        [0] "product"
    ],
     "@metadata" => {
           "_id" => "15d6f519d6827a2f28de4df1d40082d5",
        "action" => "delete",
           "seq" => 10020
    }
}

因此,它不会删除 ID 为“15d6f519d6827a2f28de4df1d40082d5”的文档,而是替换其内容。这是删除后的文档“15d6f519d6827a2f28de4df1d40082d5”,在Elasticsearch中:

curl -XGET 'localhost:9200/products/product/15d6f519d6827a2f28de4df1d40082d5?pretty'
{
  "_index" : "products",
  "_type" : "product",
  "_id" : "15d6f519d6827a2f28de4df1d40082d5",
  "_version" : 3,
  "found" : true,
  "_source" : {
    "@version" : "1",
    "@timestamp" : "2016-05-13T14:06:55.734Z",
    "type" : "product",
    "tags" : [ "product" ]
  }
}

知道为什么删除不起作用吗?这是 couchdb_changes 插件的错误吗?弹性搜索插件?

有关信息,这是我的应用程序版本: 弹性搜索 2.3.2 日志存储 2.3.2 Apache CouchDB 1.6.1

我想我找到了问题所在。 我不得不在 logstash output.elasticsearch 配置中手动添加这一行:

action => "%{[@metadata][action]}"

为了将 "delete" 从元数据传递到 Elasticsearch。

现在 upsert 出现了另一个问题,但已在 GitHub ticket 中进行了跟踪。

编辑:为了绕过upsert的问题,我其实把配置改成这样(主要是加一个字段来存储是否是删除操作):

input {
  couchdb_changes {
    host => "localhost"
    db   => "products"
    sequence_path => ".couchdb_products_seq"
    type => "product"
    tags => ["product"]
    keep_revision => true
  }
}

filter {
  if [@metadata][action] == "delete" {
      mutate {
        add_field => { "elastic_action" => "delete" }
      }
    } else {
      mutate {
        add_field => { "elastic_action" => "index" }
      }
    }
}

output {
  elasticsearch { 
    hosts => ["localhost:9200"]
    index => "products"
    document_id => "%{[@metadata][_id]}"
    action => "%{elastic_action}"
  }
  # Debug
  stdout { 
    codec => rubydebug {
      metadata => true
    } 
  }
}

我远不是 Logstash/Elasticsearch 方面的专家,但这暂时似乎有效。