写入logstash中的@timestamp



我需要将UNIX时间戳字段的值写入@timestamp,以便我可以正确地索引流经Logstash的数据,我的该部分可以正常工作。但是,我还要求@timestamp的值应该是插入时间。为此,我制作了一个临时字段,该字段持有@timestamp的原始值。

这是我正在使用的:

filter {
    csv {
        separator => "  " # <- this white space is actually a tab, don't change it, it's already perfect
        skip_empty_columns => true
        columns => ["timestamp", ...]
    }
    # works just fine
    mutate {
        add_field => {
            "tmp" => "%{@timestamp}"
        }
    }
    # works just fine
    date {
       match => ["timestamp", "UNIX"]
       target => "@timestamp"
    }
    # this works too
    mutate {
        add_field => {
            "[@metadata][indexDate]" => "%{+YYYY-MM-dd}"
        }
    }   
    # @timestamp is not being set back to its original value
    date {
        match => ["tmp", "UNIX"]
        target => "@timestamp"
    }
    # works just fine
    mutate {
        remove_field => ["tmp"]
    }
}
output {
    elasticsearch {
        hosts => "elasticsearch:9200"
        # this works
        index => "indexname-%{[@metadata][indexDate]}"
    }
}

问题在这里:

date {
    match => ["tmp", "UNIX"]
    target => "@timestamp"
}

@timestamp没有被设置回其原始值。当我检查数据时,其值与timestamp字段相同。

当您将日期添加到tmp时,它会以ISO8601格式添加,因此您需要使用:

date {
    match => ["tmp", "ISO8601"]
    target => "@timestamp"
}

最新更新