简体   繁体   English

Logstash jdbc 插件:如何对列使用日期过滤器?

[英]Logstash jdbc plugin: how use a date filter for a column?

In my MS SQL table, i have a column with date stored as string on format "dd-mm-yyyy 00:00:00.000" for example : 1999-10-06 00:00:00.000 or 2000-04-27 00:00:00.000在我的 MS SQL 表中,我有一列日期以“dd-mm-yyyy 00:00:00.000”格式存储为字符串,例如:1999-10-06 00:00:00.000 或 2000-04-27 00: 00:00.000

During my import, i want to convert this column's values into date type.在导入期间,我想将此列的值转换为日期类型。

I saw a feature called filter which could do this type of transformation.我看到了一个名为 filter 的功能,它可以进行这种类型的转换。 I found examples but only for parsing logs full text lines brought by Beats with sort of regex.我找到了一些示例,但仅用于解析 Beats 带来的带有正则表达式的日志全文行。

How to use this feature for a sql column?如何将此功能用于 sql 列? For example, how adapt this conf file for making it working for real?例如,如何调整这个 conf 文件以使其真正工作?

 input {
    jdbc {
        jdbc_connection_string => "jdbc:localhost;"
          jdbc_user => "user"
          jdbc_password => "pass"
       jdbc_driver_library => "C:\Program Files (x86)\jdbc\sqljdbc_6.0\enu\sqljdbc42.jar"
        jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
        statement => "SELECT  * FROM SOLD"
    }
}

filter
{
     date {
         match => [ "DATE_COLUMN", "YYYY-MM-dd 00:00:00.000" ]
    }
}

output {
    elasticsearch { 
       hosts => "localhost:9200"
       index => "indexname"
       document_type => "typename"

    }
}

For the moment this conf does not work and create this ES text field:目前这个 conf 不起作用并创建这个 ES 文本字段:

 "date_column": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
          }
     }
  }

so answere was to make this filter in writing the name of column in lowercase :所以答案是用小写的列名来制作这个过滤器:

filter
{
     date {
         match => [ "date_column", "yyyy-MM-dd HH:mm:ss.SSS" ]
    }
}

And to make an elasticsearch mapping column for this date format:并为此日期格式制作一个elasticsearch映射列:

PUT /index
{
     "mappings": {
      "type": {
        "properties": {
         "date_column": {
            "type": "date",
            "format": "yyyy-MM-dd HH:mm:ss.SSS"
          }
        }
      }
    }
}

If you have a field in your database called myDateField, you should get a field with the same name after using the JDBC input{}.如果您的数据库中有一个名为 myDateField 的字段,则在使用 JDBC input{} 后,您应该会得到一个同名的字段。 You can then ask logstash to process ("filter") and output this data.然后,您可以要求 logstash 处理(“过滤”)并输出此数据。

There are over 50 filters included with logstash (see the doc ). logstash 包含 50 多个过滤器(请参阅文档)。

To make your field into a date, use the date{} filter.要将您的字段设为日期,请使用日期过滤器。{} Note that this filter is usually used to set logstash's "@timestamp" field, but you can put the date into a different field (or even overwrite the same field) if you want.请注意,此过滤器通常用于设置 logstash 的“@timestamp”字段,但您可以根据需要将日期放入不同的字段(甚至覆盖同一字段)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM