我可以在Logstash中使用mutate过滤器将某些字段转换为genjdbc输入的整数吗?

时间:2015-05-05 14:30:30

标签: jdbc filter elasticsearch logstash kibana

我正在使用Logstash的genjdbc输入插件从DB2数据库中获取数据。它工作得很好,我在Kibana中将所有数据库列作为字段。 我遇到的问题是在Kibana中所有字段都是字符串类型,我希望数字字段是整数。我已经尝试了以下代码,但结果是相同的,如果不存在过滤子句。

有人可以帮我解决这个问题吗?提前谢谢!

logstash.conf代码:

  input { 
    genjdbc {  
      jdbcHost       => "XXX.XXX.XXX.XXX"
      jdbcPort       => "51260"
      jdbcTargetDB   => "db2"
      jdbcDBName     => "XXX"
      jdbcUser       => "XXX" 
      jdbcPassword   => "XXX"
      jdbcDriverPath => "C:\...\db2jcc4.jar"
      jdbcSQLQuery    => "SELECT * FROM XXX1"
      jdbcTimeField => "LOGSTAMP"
      jdbcPStoreFile => "C:\elk\logstash\bin\db2.pstore"
      jdbcURL => "jdbc:db2://XXX.XXX.XXX.XXX:51260/XXX"
      type => "table1"
    }
    genjdbc {  
      jdbcHost       => "XXX.XXX.XXX.XXX"
      jdbcPort       => "51260"
      jdbcTargetDB   => "db2"
      jdbcDBName     => "XXX"
      jdbcUser       => "XXX" 
      jdbcPassword   => "XXX"
      jdbcDriverPath => "C:\...\db2jcc4.jar"
      jdbcSQLQuery    => "SELECT * FROM XXX2"
      jdbcTimeField => "LOGSTAMP"
      jdbcPStoreFile => "C:\elk\logstash\bin\db2.pstore"
      jdbcURL => "jdbc:db2://XXX.XXX.XXX.XXX:51260/XXX"
      type => "table2"
    }
  }

  filter {
    mutate {
      convert => [ "T1", "integer" ]
      convert => [ "T2", "integer" ]
      convert => [ "T3", "integer" ]
    }
  }

  output {
    if [type] == "table1" {
      elasticsearch {
        host => "localhost"
        protocol => "http"
        index => "db2_1-%{+YYYY.MM.dd}"
      }
    }
    if [type] == "table2" {
      elasticsearch {
        host => "localhost"
        protocol => "http"
        index => "db2_2-%{+YYYY.MM.dd}"
      }
    }
  }

1 个答案:

答案 0 :(得分:2)

只要您尝试转换为整数的字段是名称T1,T2,T3并且您要插入到没有任何数据的索引中,您所拥有的就应该工作。如果索引中已有数据,则需要删除索引,以便logstash可以使用正确的映射重新创建它。