elasticsearch 日志存储:使用偏移量作为文档id,elasticsearch,logstash,filebeat,kibana-5,elasticsearch,Logstash,Filebeat,Kibana 5" /> elasticsearch 日志存储:使用偏移量作为文档id,elasticsearch,logstash,filebeat,kibana-5,elasticsearch,Logstash,Filebeat,Kibana 5" />

elasticsearch 日志存储:使用偏移量作为文档id

elasticsearch 日志存储:使用偏移量作为文档id,elasticsearch,logstash,filebeat,kibana-5,elasticsearch,Logstash,Filebeat,Kibana 5,我有以下设置: FileBeat->Logstash->Elasticsearch->Kibana(全部5.1.1) 当我将日志文件(JSON)推送到Filebeat中,如果我尝试在Kibana界面中查看它,相同的日志会被添加3-4次(重复)。 在检查完FileBeat日志后,我知道这可能是因为FileBeat没有收到发送日志的确认,因此它会继续重新发送。 要停止接收重复的文档,我想我必须在logstash配置文件中使用document\u id。 i、 e output { elas

我有以下设置:

FileBeat->Logstash->Elasticsearch->Kibana(全部5.1.1)

当我将日志文件(
JSON
)推送到Filebeat中,如果我尝试在Kibana界面中查看它,相同的日志会被添加3-4次(重复)。 在检查完FileBeat日志后,我知道这可能是因为FileBeat没有收到发送日志的确认,因此它会继续重新发送。 要停止接收重复的文档,我想我必须在logstash配置文件中使用
document\u id

i、 e

output
{ 
    elasticsearch { 
        document_id => "%{offset}"
        index => "ap-index"
        hosts => ["localhost:9222"]
    }
}
我的问题是,每个文档的偏移字段都是唯一的吗?
这是停止接收副本的正确方法吗?

如果Filebeat没有从Logstash接收到确认,这是一个迹象或问题,您应该首先找到根本原因(您的管道中可能存在阻塞)

如果有多个日志文件或执行任何日志旋转,则偏移量不是唯一的。如果日志消息包含时间戳,那么我建议使用指纹过滤器生成消息的哈希。然后在Elasticsearch中使用指纹哈希作为文档ID

input {
  beats {
    port => 5044
  }
}

filter {
  fingerprint {
    method => "SHA1"
    key    => "some_random_hmac_key"
    source => ["[beat][hostname]", "offset", "message"]
    concatenate_sources => true
    target => "[@metadata][id]"
  }
}

output {
  elasticsearch {
    hosts => "localhost:9200"
    manage_template => false
    index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
    document_type => "%{[@metadata][type]}"
    document_id =>"%{[@metadata][id]}"
  }
}

我可能有一个以上的日志文件,是的,可以有一个日志循环。而且我的时间戳可能不是唯一的。在这种情况下,散列可以不同??您可以修改该散列以合并Filebeat给定的偏移量。如果你的时间戳分辨率很低,比如秒,我会这样做。我将更新答案以包含偏移量。