【问题标题】:elasticsearch - import csv using logstash date is not parsed as of datetime typeelasticsearch - 使用 logstash 导入 csv 日期不解析为 datetime 类型
【发布时间】:2017-11-16 11:57:38
【问题描述】:

我正在尝试使用 logstash 将 csv 导入 elasticsearch 我尝试了两种方式:

  1. 使用 CSV
  2. 使用 grok 过滤器

1) 下面的 csv 是我的 logstash 文件:

input {
  file {
    path => "path_to_my_csv.csv"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}
filter {
  csv {
        separator => ","
        columns => ["col1","col2_datetime"]
  }
  mutate {convert => [ "col1", "float" ]}
  date {
        locale => "en"
        match => ["col2_datetime", "ISO8601"] // tried this one also - match => ["col2_datetime", "yyyy-MM-dd HH:mm:ss"]
        timezone => "Asia/Kolkata"
        target => "@timestamp" // tried this one also - target => "col2_datetime"
   }
}
output {
   elasticsearch {
     hosts => "http://localhost:9200"
     index => "my_collection"

  }
  stdout {}
}

2) 使用 grok 过滤器:

下面的 grok 过滤器是我的 logstash 文件

input {
  file {
    path => "path_to_my_csv.csv"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}
filter {
  grok {
    match => { "message" => "(?<col1>(?:%{BASE10NUM})),(%{TIMESTAMP_ISO8601:col2_datetime})"}
    remove_field => [ "message" ]
  }
  date {
        match => ["col2_datetime", "yyyy-MM-dd HH:mm:ss"]
   }
}
output {
   elasticsearch {
     hosts => "http://localhost:9200"
     index => "my_collection_grok"

  }
  stdout {}
}

问题:

因此,当我单独运行这两个文件时,我可以在 elasticsearch 中导入数据。但是我的日期字段没有被解析为日期时间类型,而是被保存为字符串,因此我无法运行日期过滤器。

所以有人可以帮我弄清楚为什么会这样。 我的 elasticsearch 版本是 5.4.1。

提前致谢

【问题讨论】:

  • 您能分享一下您的 CSV 文件中的几行吗?
  • 请查看这个 1234365,2016-12-02 19:00:52 1234368,2016-12-02 15:02:02 1234369,2016-12-02 15:02:07

标签: elasticsearch logstash logstash-grok


【解决方案1】:

我对您的配置文件做了 2 处更改。

1) 删除列名 col2_datetime 中的下划线

2) 添加目标

这是我的配置文件的样子...

vi logstash.conf

input {
  file {
    path => "/config-dir/path_to_my_csv.csv"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}
filter {
  csv {
        separator => ","
        columns => ["col1","col2"]
  }
  mutate {convert => [ "col1", "float" ]}
  date {
        locale => "en"
        match => ["col2",  "yyyy-MM-dd HH:mm:ss"]
        target => "col2"
   }
}
output {
   elasticsearch {
     hosts => "http://172.17.0.1:9200"
     index => "my_collection"

  }
  stdout {}
}

这是数据文件:

vi path_to_my_csv.csv

1234365,2016-12-02 19:00:52 
1234368,2016-12-02 15:02:02 
1234369,2016-12-02 15:02:07

【讨论】:

  • 它仍然作为字符串插入
  • Logstash 版本?我用 5.4 版本测试过。
  • 我的也一样
  • 谢谢它的工作,我在 kibana 中使用了不正确的日期过滤器
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-10
  • 1970-01-01
  • 1970-01-01
  • 2013-05-07
  • 2023-03-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多