Elasticsearch mysql 增量同步處理 三表聯合 指令碼

來源:互聯網
上載者:User

標籤:concat   mysq   ast   資料   運行   idc   add   判斷   使用教程   

從上方外掛程式官網中下載適合的dist包,然後解壓。進入bin目錄,可以看到一堆sh指令碼。在bin目錄下建立一個test.sh:

bin=/home/csonezp/Dev/elasticsearch-jdbc-2.3.1.0/bin
lib=/home/csonezp/Dev/elasticsearch-jdbc-2.3.1.0/lib
echo ‘{
"type" : "jdbc",
"statefile" : "statefile.json",
"jdbc": {
"url" : "jdbc:mysql://myaddr",
"user" : "myuser",
"password" : "mypwd",
"type" : "mytype",
"index": "myindex",
"schedule" : "0 * * * * ?",
"metrics" : {"enabled" : true
},
"sql" : [{ "statement" : "select * from gd_actor_info where update_time > ?", "parameter" : [ "$metrics.lastexecutionstart" ]}
]
}
}‘ | java \
-cp "${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter

schedule現在設定成每分鐘都執行一次,是為了方便觀察行為。statefile這一句是一定要加的。$metrics.lastexecutionstart就是這個指令碼的關鍵所在了,這個指的是上一次指令碼執行的時間,可以通過比較這個時間和資料庫裡的欄位來判斷是否要更新。

Elasticsearch mysql 增量同步處理 三表聯合 指令碼

上面簡略的說了一下es同步資料指令碼的大致情況,但是實際情況裡肯定不會像上一篇裡面的指令碼那麼簡單。比如目前我就有三張表,兩張實體表,一張關聯表。大致實現如下:

bin目錄建立一個statefile.json檔案:

{
"type" : "jdbc",
"statefile" : "statefile.json",
"jdbc": {
"url" : "jdbc:mysql://",
"user" : "",
"password" : "",
"type" : "actor",
"index": "test",
"schedule" : "0 * * * * ?",
"metrics" : { 
"lastexecutionstart" : "0",
"lastexecutionend" : "0",
"counter" : "1" 
}, 
"sql" : [{ "statement" : "select a.actor_id as _id ,a.*,GROUP_CONCAT(b.tag_name ) as tag_name from ( ( gd_actor_info as a left join gd_actor_tag as ab on a.actor_id = ab.actor_id ) left join gd_tag_actor as b on ab.tag_id = b.tag_id) where a.update_time >? or ab.update_time > ? group by a.actor_id ", "parameter" : [ "$metrics.lastexecutionstart" ,"$metrics.lastexecutionstart" ]}
]
}
}

主要是lastexecutionstart設定為0,為了讓第一次執行能進行一次全量備份。

其實sh指令碼資訊也就都在上面了,再寫一個就好了

Elasticsearch 最新版本 2.20 發布下載了 http://www.linuxidc.com/Linux/2016-02/128166.htm

Linux上安裝部署Elasticsearch全程記錄 http://www.codesec.net/Linux/2015-09/123241.htm

Elasticsearch安裝使用教程 http://www.codesec.net/Linux/2015-02/113615.htm

Elasticsearch 設定檔譯文解析 http://www.codesec.net/Linux/2015-02/114244.htm

Elasticsearch叢集搭建執行個體 http://www.codesec.net/Linux/2015-02/114243.htm

分布式搜尋Elasticsearch單機與伺服器環境搭建 http://www.codesec.net/Linux/2012-05/60787.htm

Elasticsearch的工作機制 http://www.codesec.net/Linux/2014-11/109922.htm

Elasticsearch的安裝,運行和基本配置 http://www.codesec.net/Linux/2016-07/2881064151.htm

使用Elasticsearch + Logstash + Kibana搭建日誌集中分析平台實踐 http://www.codesec.net/Linux/2015-12/126587.htm

Ubuntu 14.04搭建ELK日誌分析系統(Elasticsearch+Logstash+Kibana) http://www.codesec.net/Linux/2016-06/132618.htm

Elasticsearch1.7升級到2.3實踐總結 http://www.codesec.net/Linux/2016-11/137282.htm

Elasticsearch mysql 增量同步處理 三表聯合 指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.