ElasticSearch中的嵌套对象与MySQL数据

时间:2016-05-16 09:46:29

标签: elasticsearch logstash kibana-4 logstash-configuration

我是ES新手并尝试使用logstash jdbc将数据从MYSQL加载到Elasticsearch。

在我的情况下,我想将列值用作字段名称,请参阅新的&输出数据中的十六进制,我想要' id'值作为字段名称。

Mysql数据

cid    id       color      new     hex      create            modified
1      101     100 euro    abcd   #86c67c  5/5/2016 15:48   5/13/2016 14:15
1      102     100 euro    1234   #fdf8ff  5/5/2016 15:48   5/13/2016 14:15

需要输出

{
  "_index": "colors_hexa",
  "_type": "colors",
  "_id": "1",
  "_version": 218,
  "found": true,
  "_source": {
    "cid": 1,
    "color": "100 euro",
    "new" : {
            "101": "abcd",
            "102": "1234",
        }
    "hex" : {
            "101": "#86c67c",
            "102": "#fdf8ff",
        }
    "created": "2016-05-05T10:18:51.000Z",
    "modified": "2016-05-13T08:45:30.000Z",
    "@version": "1",
    "@timestamp": "2016-05-14T01:30:00.059Z"
  }
}

Logstash config:

input {
 jdbc {
   jdbc_driver_library => "/etc/logstash/mysql/mysql-connector-java-5.1.39-bin.jar"
   jdbc_driver_class => "com.mysql.jdbc.Driver"
   jdbc_connection_string => "jdbc:mysql://127.0.0.1:3306/test"
   jdbc_user => "root"
   jdbc_password => "*****"
   schedule => "* * * * *"

   statement => "select cid,id,color, new ,hexa_value ,created,modified from colors_hex_test order by cid"
   jdbc_paging_enabled => "true"
   jdbc_page_size => "50000"
}
}

   output {
    elasticsearch {
        index => "colors_hexa"
        document_type => "colors"
        document_id => "%{cid}"
        hosts => "localhost:9200"
    }
}

任何人都可以帮助我们为这些数据提供过滤器代码,' new' &安培; '十六进制'字段是这里的问题。我试图将两个记录转换为单个文档。

0 个答案:

没有答案