GithubHelp home page GithubHelp logo

mysql2es's Introduction

MariaDB to es

同步 MariaDB 表的数据到 es 的精简版本, 只支持添加和更新, 不支持物理删除的更新, 建议使用逻辑删除.

基于 jdk 8 和 spring boot, 支持 es 5.1.1(截至 2017 年 1 月)

相关的配置(application.yml)如下:

config:
  ip-port: ["127.0.0.1:9300"]     # 可以不设定, 默认是 127.0.0.1:9300
  cron: 0 * * * * *               # 可以不设定, 默认是每分钟执行一次

  index: platform                 # *** 必须设定. 表示 es 中 /index/type/id 的 index, 与 database name 对应
  relation:
    -
      table: T_PRODUCT            # *** 必须设定且要有主键. 主键会生成 es 中 /index/type/id 的 id, 主键如果多个将会拼接
      increment-column: ["ID"]    # *** 必须设定. 表示用来做数据增量操作时用, 使用 id 和 updateTime(更新时间戳)

    -
      table: T_SOME               # *** 必须设定且要有主键
      increment-column: ["ID"]    # *** 必须设定

      type: some                  # 表示 es 中 /index/type/id 的 type, 不设定将会从数据库表名生成(t_some_one ==> someOne)
      sql: select * from T_SOME   # 自定义的 sql 语句, 不设定将会自动从数据库表拼装
      limit: 10                   # 一次从数据库获取的条数, 默认是 20
      mapping:                    # 对应关系.「db column」:「es field」, 不设定将会从表字段生成(c_id_name ==> idName)
        ID: id
        NAME: name
        CREATE_TIME: createTime
        UPDATE_TIME: updateTime
        IS_DELETE: isDelete

cron 的说明如下

.------------------- second (0 - 59)   if (0/10) then (0, 10, 20, 30, 40, 50) run
.  .---------------- minute (0 - 59)
.  .  .------------- hour (0 - 23)
.  .  .  .---------- day of month (1 - 31)
.  .  .  .  .------- month (1 - 12)   OR jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec
.  .  .  .  .  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
.  .  .  .  .  .
?  *  *  *  *  *

如  0/5 * * * * *  表示每 5 秒运行一次

运行

mvn clean package; nohup java -jar -Dspring.profiles.active=prod target/mysql2es-1.0-SNAPSHOT.jar >/dev/null 2>&1 &

or

nohup mvn spring-boot:run -Dspring.profiles.active=prod >/dev/null 2>&1 &

说明

项目在启动时会基于配置进行数据库查询, 将相关的表结构保存至 es.
而后定时器会在每分钟从临时文件读取值查询并同步进 es 且将最后的值写进临时文件.

PS : 第一次运行时可以将定时任务的周期尽量短一点, 比如 5 秒一次.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.