将数据同步到es并自定义es索引结构

时间:2018-10-26 05:39:35

标签: elasticsearch logstash

我有两个表:customer,customer_order 客户有customer_name,sex,customerid列。 我想将两个表同步到elasticsearch customerOrder索引 customerOrder结构,如

{
  orderid:x,
  ordercreatetime,
  customerinfo:{
    customername:xx,
    sex:x
    customerid:xx
  }
}

我的问题是,如何使两个表数据同步并集成到自定义的es索引结构,例如:customerOrder 当customer_name在customer表中更改时,我想更改所有customerOrder索引的customername字段值。 感谢您的所有建议!

这是logstash.conf

input {
  jdbc {
    jdbc_driver_library => "/opt/logstash-6.3.0/mssql-jdbc-7.0.0.jre8.jar"
    jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    jdbc_connection_string => "jdbc:sqlserver://xxxxx;databaseName=xxxx;"
    jdbc_user => "xx"
    jdbc_password => "xxx"
    statement => "select  * from customer_order"
    jdbc_paging_enabled => "true"
    jdbc_page_size => "5000"
    schedule => "* * * * *"
    use_column_value => true
    tracking_column => "orderid"
    tracking_column_type => "numeric"

  }
  jdbc {
    jdbc_driver_library => "/opt/logstash-6.3.0/mssql-jdbc-7.0.0.jre8.jar"
    jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    jdbc_connection_string => "jdbc:sqlserver://xxxxx;databaseName=xxxx;"
    jdbc_user => "xx"
    jdbc_password => "xxx"
    statement => "select  * from customer"
    jdbc_paging_enabled => "true"
    jdbc_page_size => "5000"
    schedule => "* * * * *"
    use_column_value => true
    tracking_column => "customerid"
    tracking_column_type => "numeric"

  }
}
filter {

}
output {

  elasticsearch {
    hosts => ["http://xxxxxx"]
    index => "customerOrder"
    document_id => "%{orderid}"
    user => "xx"
    password => "xxx"
  }
  stdout { codec => rubydebug }
}

0 个答案:

没有答案