mysql作为数据源导入elasticsearch

logstash 主配文件

    input {
        jdbc {
        #连接数据库的驱动jar包位置
        jdbc_driver_library => "./mysql-connector-java-5.1.45.jar"
        #连接mysql必须配置 
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        jdbc_connection_string =>"*****"
        jdbc_user => "name"
        jdbc_password => "password"
        #分页配置  默认100000
        jdbc_page_size => 100000
        jdbc_paging_enabled => true
        #连接数据库的查询语句
        statement => "select * from dx_weak_bind"
        #记录位置
        last_run_metadata_path => "./syncpoint_table4.log"
      }
    }
    output {
        elasticsearch {	
            # es 地址
            hosts => "es.com:9200"
            # 索引名称
            index => "dx_weak_bind"
            # document_id  默认自己生成 可也有数据库赋值
            document_id => "%{id}" 
            manage_template => true
	    template_overwrite => true
	    # 模板名称对应下面的模板文件名称
            template_name => "dx_weak_bind"
	    # 模板位置
            template => "./config/template-mysql4.json"
      }
    }

生成maaping模板配置文件 详细mapping

    {
        #模板名称
	"template": "name",
	"settings": {
                # 设置分片数量
		"index.number_of_shards": 3,
		"number_of_replicas": 1,
		# 设置查入响应时间
                "index.refresh_interval": "60s"
	},
	"mappings": {
		"doc": {
			"properties": {
				"itemid": {
					"type": "integer"
				},
				"activity_itemid": {
					"type": "keyword"
				}
			}
		}
	}
} 
原文地址:https://www.cnblogs.com/MND1024/p/10980117.html