2016-05-13 85 views
3

我試圖使用couchdb_changes Logstash插件來檢測我的CouchDB更改並充分更新Elasticsearch索引。Logstash couchdb_changes沒有正確地將文檔刪除傳播到Elasticsearch

文檔創作/更新工作正常,但不知何故刪除不起作用。

這裏是我的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但「協議」參數中elasticsearch Logstash插件不再存在,我希望這樣一個巨大的錯誤到現在是固定的。

在我Logstash控制檯我看到這個的時候我刪除一個CouchDB文檔(從被褥):

{ 
     "@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插件的錯誤嗎? elasticsearch插件?

的信息,這裏有我的應用程序版本: Elasticsearch 2.3.2 Logstash 2.3.2 的Apache CouchDB的1.6.1

回答

4

我想我找到了問題。 我曾在logstash output.elasticsearch配置手動添加這一行:

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

爲了通過從元數據中的「刪除」來Elasticsearch。

現在還有一個upsert的問題,但它的跟蹤在GitHub ticket

編輯:爲了繞過theupsert問題,我竟然改變了我的配置,這(主要是添加一個字段存儲的動作是否是刪除):

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,但這似乎目前工作。