我将Logstash 1.4.1与ES1.01一起使用,并希望根据计算的校验和替换已编入索引的文档。我目前正在使用"指纹"在Logstash中过滤,创建一个"指纹"字段基于指定的算法。现在 - 我想要完成的是ES 基于相同的指纹值替换现有文档。
比如说,我有一个指纹字段值为" 2c9a6802e10fbcff36177e0b88993f90868fa6fa"的文档。现在 - 如果要将具有相同指纹值的文档编入索引,我希望它替换索引中已存在的旧文档。
我试图将以下内容添加到" elasticsearch-template.json"我假设的模板文件由Logstash ES输出插件使用:
...
"mappings" : {
"_default_" : {
"_id" : {"index": "not_analyzed", "store" : false, "path" : "fingerprint" },
"_all" : {"enabled" : true},
"dynamic_templates" : [ {
...
但它不起作用。我在这里做错了什么?
干杯
答案 0 :(得分:15)
我会在你的logstash elasticsearch输出部分中使用document_id参数:
<强> DOCUMENT_ID 强>
Value type is string Default value is nil
索引的文档ID。用于覆盖现有条目 在Elasticsearch中具有相同的ID。
我认为参赛作品应该是这样的:
document_id => "%{fingerprint}"
它使用logstash的sprintf格式将字符串替换为字段的内容:
https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#sprintf
答案 1 :(得分:2)
假设指纹设置为_id,您可能遇到了logstash的每日索引管理问题,而没有使用数据中的时间戳。
确保您已根据输入数据设置了时间戳,因此可以保证文档的每日索引正确:
http://logstash.net/docs/1.4.2/filters/date
如果我的猜测是正确的,您应该会看到您的重复文档具有不同的@timestamp并且位于不同的每日索引中。
答案 2 :(得分:0)
您可以将document_id设置为指纹过滤器计算出的值,这会将指纹值放入写入索引的文档的_id
字段中。由于_id
在任何给定的索引中必须是唯一的,因此任何写入相同_id
值的文档都将被覆盖并进行重复数据删除。
以下博客文章提供了如何实现此目的的示例: https://www.elastic.co/blog/logstash-lessons-handling-duplicates https://alexmarquardt.com/2018/07/23/deduplicating-documents-in-elasticsearch/
免责声明:我是Elastic的咨询工程师。