<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                使用Lua腳本可以實現更復雜的數據處理邏輯,go-mysql-transfer支持Lua5.1語法 # **示例** t_user表,數據如下: ![](https://img.kancloud.cn/72/5f/725f91f8dd6beb960b8de8872b9512f3_600x89.jpg) ## **示例一** 引入Lua腳本: ``` rule: - schema: eseap #數據庫名稱 table: t_user #表名稱 order_by_column: id #排序字段,存量數據同步時不能為空 lua_file_path: lua/t_user_es.lua #lua腳本文件 es_index: user_index #Elasticsearch Index名稱,可以為空,默認使用表(Table)名稱 es_mappings: #索引映射,可以為空,為空時根據數據類型自行推導ES推導 - field: id #映射后的ES字段名稱 type: keyword #ES字段類型 - field: userName #映射后的ES字段名稱 type: keyword #ES字段類型 - field: password #映射后的ES字段名稱 type: keyword #ES字段類型 - field: createTime #映射后的ES字段名稱 type: date #ES字段類型 format: yyyy-MM-dd HH:mm:ss #日期格式,type為date此項有意義 - field: remark #映射后的ES字段名稱 type: text #ES字段類型 analyzer: ik_smart #ES分詞器,type為text此項有意義 - field: source #映射后的ES字段名稱 type: keyword #ES字段類型 ``` 其中, es_mappings 表示索引的mappings(映射關系),不定義es_mappings則根據字段的值自動創建mappings(映射關系)。根據es_mappings 生成的mappings如下: ![](https://img.kancloud.cn/08/57/08573c3be355c9dfadda240a18a009c7_433x480.png) Lua腳本: ``` local ops = require("esOps") --加載elasticsearch操作模塊 local row = ops.rawRow() --當前數據庫的一行數據,table類型,key為列名稱 local action = ops.rawAction() --當前數據庫事件,包括:insert、update、delete local id = row["ID"] --獲取ID列的值 local userName = row["USER_NAME"] --獲取USER_NAME列的值 local password = row["PASSWORD"] --獲取USER_NAME列的值 local createTime = row["CREATE_TIME"] --獲取CREATE_TIME列的值 local remark = row["REMARK"] --獲取REMARK列的值 local result = {} -- 定義一個table,作為結果集 result["id"] = id result["userName"] = userName result["password"] = password result["createTime"] = createTime result["remark"] = remark result["source"] = "binlog" -- 數據來源 if action == "insert" then -- 只監聽新增事件 ops.INSERT("t_user",id,result) -- 新增,參數1為index名稱,string類型;參數2為要插入的數據主鍵;參數3為要插入的數據,tablele類型或者json字符串 end ``` 同步到Elasticsearch的數據如下: ![](https://img.kancloud.cn/de/5d/de5dbc46fcbb9cebd95d6e04643acef3_432x276.png) ## **示例二** 引入Lua腳本: ``` schema: eseap #數據庫名稱 table: t_user #表名稱 lua_file_path: lua/t_user_es2.lua #lua腳本文件 ``` 未明確定義index名稱、mappings,es會根據值自動創建一個名為t_user的index。 使用如下腳本: ``` local ops = require("esOps") --加載elasticsearch操作模塊 local row = ops.rawRow() --當前數據庫的一行數據,table類型,key為列名稱 local action = ops.rawAction() --當前數據庫事件,包括:insert、update、delete local id = row["ID"] --獲取ID列的值 local userName = row["USER_NAME"] --獲取USER_NAME列的值 local password = row["PASSWORD"] --獲取USER_NAME列的值 local createTime = row["CREATE_TIME"] --獲取CREATE_TIME列的值 local result = {} -- 定義一個table,作為結果集 result["id"] = id result["userName"] = userName result["password"] = password result["createTime"] = createTime result["remark"] = remark result["source"] = "binlog" -- 數據來源 if action == "insert" then -- 只監聽新增事件 ops.INSERT("t_user",id,result) -- 新增,參數1為index名稱,string類型;參數2為要插入的數據主鍵;參數3為要插入的數據,tablele類型或者json字符串 end ``` 同步到Elasticsearch的數據如下: ![](https://img.kancloud.cn/b8/ec/b8ec66ee15cc7ee366623fadf8552258_439x272.png) # **esOps模塊** 提供的方法如下: 1. INSERT: 插入操作,如:ops.INSERT(index,id,result)。參數index為索引名稱,字符串類型;參數index為要插入數據的主鍵;參數result為要插入的數據,可以為table類型或者json字符串 2. UPDATE: 修改操作,如:ops.UPDATE(index,id,result)。參數index為索引名稱,字符串類型;參數index為要修改數據的主鍵;參數result為要修改的數據,可以為table類型或者json字符串 3. DELETE: 刪除操作,如:ops.DELETE(index,id)。參數index為索引名稱,字符串類型;參數id為要刪除的數據主鍵,類型不限;
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看