elasticsearch-jdbc 例子

本文介绍如何使用JDBCImporter工具将MySQL数据库中的数据同步到Elasticsearch中。通过配置文件定义了数据源、目标索引及字段映射等信息,并使用Shell脚本执行同步任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/bin/sh

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

bin=${DIR}/../bin

lib=${DIR}/../lib

echo '{

"type" : "jdbc",

"jdbc": {

"elasticsearch.autodiscover":true,

"elasticsearch.cluster":"company",

"url":"jdbc:mysql://***:3306/es",

"user":"***",

"password":"***",

"sql":"SELECT id as _id , id, name, status, type,  full_name, frequency, gmt_modified  FROM  table",

"elasticsearch" : {

  "host" : "***.***.***.***",

  "port" : 9300

},

"index" : "searchsuggestion-temp",

"type" : "searchsuggestion-temp",

"type_mapping": {

     "searchsuggestion-temp": {


      "properties": {

        

           "id": {

          "type" : "long",

   "include_in_all" : false

        },

        "name": {

           "type" : "string",

   "index" : "not_analyzed",

   "include_in_all" : false

        },

"status": {

           "type" : "integer",

   "include_in_all" : false

        },

"type": {

           "type" : "integer",

   "include_in_all" : false

        },

"full_name": {

           "type" : "string",

   "index" : "not_analyzed",

   "include_in_all" : false

        },

"frequency": {

           "type" : "integer",

   "include_in_all" : false

        },

         "gmt_modified": {

           "type" : "date",

   "include_in_all" : false

        }


      }

      }

  }}

}'| java \

  -cp "${lib}/*" \

  -Dlog4j.configurationFile=${bin}/log4j2.xml \

  org.xbib.tools.Runner \

  org.xbib.tools.JDBCImporter



本文转自whk66668888 51CTO博客,原文链接:http://blog.51cto.com/12597095/1909404
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值