如何通过组合输入csv的两个字段/列来在logstash中生成@timestamp

时间:2015-03-05 13:37:29

标签: csv elasticsearch logstash

我们在csv文件中有来自外部资源的数据:

orderid,OrderDate,BusinessMinute,Quantity,Price
31874,01-01-2013,00:06,2,17.9

数据在一列中有date,在另一列中有time - 我需要通过将这两列组合在一起来生成时间戳。

我正在使用csv filter使用logstash中的以下配置从文件中读取上述数据 - 这正在生成自己的时间戳:

input {  
  file {
      path => "/root/data/import/Order.csv"
      start_position => "beginning"
  }
}
filter {
    csv {
        columns => ["orderid","OrderDate","BusinessMinute","Quantity","Price"]
        separator => ","
    } 
}
output {  
    elasticsearch {
        action => "index"
        host => "localhost"
        index => "demo"
        workers => 1
    }
}

如何将OrderDate + Business Minute组合为@timestamp

1 个答案:

答案 0 :(得分:16)

使用mutate filter将OrderDate和BusinessMinute字段合并为一个(临时)字段,然后使用date filter并删除该字段,如果该字段成功。

filter {
  mutate {
    add_field => {
      "timestamp" => "%{OrderDate} %{BusinessMinute}"
    }
  }
  date {
    match => ["timestamp", "..."]
    remove_field => ["timestamp"]
  }
}