Search code examples
elasticsearchlogstashkibana-4logstash-configuration

load array data mysql to ElasticSearch using logstash jdbc


Hi i am new to ES and i m trying to load data from 'MYSQL' to 'Elasticsearch'

I am getting below error when trying to loadata in array format, any help

Here is mysql data, need array data for new & hex value columns

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

Here us the 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,color, new as 'cvalue.new',hexa_value as 'cvalue.hexa',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"

Need array data for cvalue (new, hexa) like

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

this is the error i m getting while running logstash

 "status"=>400, "error"=>{"type"=>"mapper_parsing_exception",
 "reason"=>"Field name [cvalue.hexa] cannot contain '.'"}}}, :level=>:warn}

Solution

  • You cant give a field name with .. But you can try to add:

    filter {
      mutate {
        rename => { "new" => "[cvalue][new]" }
        rename => { "hexa" => "[cvalue][hexa]" }
      }
    }