How to compare date in Logstash

Viewed 1882

How to compare date in logstash. I want to compare date with a constant date value. The below code fails in Logstash with ruby exception.

if [start_dt] <= "2016-12-31T23:23:59.999Z"
1 Answers

I finally figured it out. First convert the constant date from string to date using logstash date plugin. Then you can compare this date with your date field.

            mutate{
                 add_field => { "str_dt" => "2016-12-31T23:23:59.999Z"}
            }
            date {
                match => ["str_dt", "YYYY-MM-dd'T'HH:mm:ss.SSSZ"]
                target => "constant_date"
            }

            if [start_dt] <= [constant_date] {
            }
Related