你不会是程序猿吧?

logstash同步postgresql数据库到ES,索引类型设置失效,全部变成了doc [问

Logstash | 作者 狐妖小红娘 | 发布于2018年08月13日 | 阅读数:3983

用logstash-input-jdbc插件同步postgresql数据库表到elasticsearch中!设置索引类型失效,全部成了doc索引类型
下面的是我的jdbc.conf配置
  input {
    stdin {
    }
    jdbc {
      # 数据库
      jdbc_connection_string => "jdbc:postgresql://localhost:5432/story"
      # 用户名密码
      jdbc_user => "tzdr"
      jdbc_password => "1225"
      # 数据库驱动jar包的位置
      jdbc_driver_library => "E:/logstash-6.3.1/bin/postgresql/postgresql-9.4.1212.jar"
      # postgresql的Driver
      jdbc_driver_class => "org.postgresql.Driver"
      jdbc_paging_enabled => "true"
      jdbc_page_size => "50000"
      #statement_filepath => "E:/logstash-6.3.1/bin/postgresql/jdbc.sql"
      statement => "select * from book"
      schedule => "* * * * *"
      #索引的类型
      type => "book"
    }
    
    jdbc {
      # 数据库
      jdbc_connection_string => "jdbc:postgresql://localhost:5432/story"
      # 用户名密码
      jdbc_user => "tzdr"
      jdbc_password => "1225"
      # 数据库驱动jar包的位置
      jdbc_driver_library => "E:/logstash-6.3.1/bin/postgresql/postgresql-9.4.1212.jar"
      # postgresql的Driver
      jdbc_driver_class => "org.postgresql.Driver"
      jdbc_paging_enabled => "true"
      jdbc_page_size => "50000"
      #statement_filepath => "E:/logstash-6.3.1/bin/postgresql/jdbc.sql"
      statement => "select * from want"
      schedule => "* * * * *"
      #索引的类型
      type => "want"
    }
   
}

filter {
    json {
        source => "message"
        remove_field => ["message"]
    }
}
output {
       if [type]=="book"{
         elasticsearch {
            hosts => "127.0.0.1:9200"
            # index名
            index => "myself"
            # 需要关联的数据库中有有一个id字段,对应索引的id号   前面记得要%号
            document_id => "%{istrue}"
         }
       }
       if [type]=="want"{
         elasticsearch {
            hosts => "127.0.0.1:9200"
            # index名
            index => "myself"
            # 需要关联的数据库中有有一个id字段,对应索引的id号   前面记得要%号
            document_id => "%{id}"
         }
       }
   
    stdout {
        codec => json_lines
    }
}
**************************************

head截图.png


 
已邀请:

rochy - rochy_he

赞同来自:

你的 Type 设置到 output 的配置中,设置到 input 无效的

狐妖小红娘

赞同来自:

问题已经解决了!谢谢大家
原来从ES 6.0后开始慢慢的开始不再支持doc_type,不再和传统的数据库table那样从概念上去对应
可以让所有的文档_type都是doc类型,logstash同步的时候会添加一个type字段,查询的时候加条件就可以
也可以每个类型,直接对应不同的索引!不过感觉那样会比较累赘
 

zqc0512 - andy zhou

赞同来自:

6 为了性能修改了些。一个索引一个type 
5可以。

要回复问题请先登录注册