0

I need to write the value of a UNIX timestamp field to @timestamp so that I can correctly index data flowing through logstash, I have this part working. However I also have the requirement that @timestamp's value should be the insertion time. To this end I have made a temporary field that holds @timestamps original value.

Here is what I am working with:

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]}"
    }
}

The Problem is here:

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

@timestamp is not being set back to its original value. When I check the data it has the same value as the timestamp field.

4

1 回答 1

2

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

date {
    match => ["tmp", "ISO8601"]
    target => "@timestamp"
}
于 2017-02-16T14:58:34.553 回答