繁体   English   中英

如何将输入文档字段映射到elasticsearch _id字段?

[英]how to map an input document field to the elasticsearch _id field?

我有一个相当简单的管道,用于从Kafka获取json消息并将其发送到Elasticsearch:

input {
    kafka {
        bootstrap_servers =>  "kafka04-prod01.messagehub.services.eu-de.bluemix.net:9093,kafka05-prod01.messagehub.services.eu-de.bluemix.net:9093,kafka01-prod01.messagehub.services.eu-de.bluemix.net:9093,kafka03-prod01.messagehub.services.eu-de.bluemix.net:9093,kafka02-prod01.messagehub.services.eu-de.bluemix.net:9093"
        topics => [ "transactions_load" ]
    }
}
filter {
  json {
    source => "message"
  }
  mutate{
    remove_field => ["kafka"]
    remove_field => ["@version"]
    remove_field => ["@timestamp"]
    remove_field => ["message"]
    remove_tag => ["multiline"]
  }
}
output {
    elasticsearch {
        hosts => [
                "xxxxx.ibm-343.composedb.com:16915",
                "xxxxx.ibm-343.composedb.com:16915"
            ]
        ssl => true
        user => "logstash_kafka"
        password => "*****"
        index => "pos_transactions"
    }
}

json记录具有一个TransactionID字段,用于唯一标识每个记录:

{"TransactionID": "5440772161", "InvoiceNo": 5440772, "StockCode": 22294, "Description": "HEART FILIGREE DOVE  SMALL", "Quantity": 4, "InvoiceDate": 1507777440000, "UnitPrice": 1.25, "CustomerID": 14825, "Country": "United Kingdom", "LineNo": 16, "InvoiceTime": "03:04:00", "StoreID": 1}
{"TransactionID": "5440772191", "InvoiceNo": 5440772, "StockCode": 21733, "Description": "RED HANGING HEART T-LIGHT HOLDER", "Quantity": 4, "InvoiceDate": 1507777440000, "UnitPrice": 2.95, "CustomerID": 14825, "Country": "United Kingdom", "LineNo": 19, "InvoiceTime": "03:04:00", "StoreID": 1}

我可以配置logstash来使用TransactionID作为_id字段,以便如果我为同一事务处理重复记录时,这些更新是幂等的?

我自己想出了答案。 在此处发布,因为它可能对其他人有用:

output {
    elasticsearch {
        hosts => [
                "xxxxx.ibm-343.composedb.com:16915",
                "xxxxx.ibm-343.composedb.com:16915"
            ]
        ssl => true
        user => "logstash_kafka"
        password => "*****"
        index => "pos_transactions"
        document_id => "%{TransactionID}"
    }
}

document_id => "%{TransactionID}"配置条目将传入文档TransactionID字段用于elasticsearch _id

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM