標籤:use file log nbsp 個數 安裝 ros put select
====== mysql的river介紹======
- 什麼是river?river代表es的一個資料來源,也是其它儲存方式(如:資料庫)同步資料到es的一個方法。它是以外掛程式方式存在的一個es服務,通過讀取river中的資料並把它索引到es中,官方的river有couchDB的,RabbitMQ的,Twitter的,Wikipedia的。這裡主要研究針對mysql的river。
- mysql的river外掛程式:mysql的river安裝見https://github.com/jprante/elasticsearch-river-jdbc,就不具體介紹了。
- 實踐測試:
* 環境:
伺服器172.16.170.21 資料庫:profile 表user
* 建立索引
curl -XPUT ‘http://localhost:9200/profile‘
* 建立資料表與索引映射
curl -XPUT ‘http://localhost:9200/profile/user/_mapping‘ -d ‘
{
"user": {
"properties": {
"id": {
"type": "string",
"store": "yes"
},
"name": {
"type": "string",
"store": "yes"
},
"login_name": {
"type": "string",
"store": "yes"
}
}
}
}‘
* 運行river同步資料
curl -XPUT ‘http://localhost:9200/_river/who_jdbc_river/_meta‘ -d ‘{
"type": "jdbc",
"jdbc": {
"driver": "com.mysql.jdbc.Driver",
"url": "jdbc:mysql://localhost:3306/profile",
"user": "root",
"password": "root",
"sql": "select id as _id,name,login_name from user",
"index": "profile",
"type": "user",
"bulk_size": 100,
"max_bulk_requests": 30,
"bulk_timeout": "10s",
"flush_interval": "5s",
"schedule": "0 0-59 0-23 ? * *"
}
}‘
* 累加式更新索引
累加式更新,表需要維護時間戳記,發現時間戳記更新的列需要更新
curl -XPUT ‘http://localhost:9200/_river/who_jdbc_river/_meta‘ -d ‘{
"type": "jdbc",
"jdbc": {
"driver": "com.mysql.jdbc.Driver",
"url": "jdbc:mysql://localhost:3306/profile",
"user": "root",
"password": "root",
"sql": [
{
"statement": "select id as _id,name,login_name from user where mytimestamp > ?",
"parameter": [
"$river.state.last_active_begin"
]
}
],
"index": "profile",
"type": "user",
"bulk_size": 100,
"max_bulk_requests": 30,
"bulk_timeout": "10s",
"flush_interval": "5s",
"schedule": "0 0-59 0-23 ? * *"
}
}‘
刪除river
curl -XDELETE ‘localhost:9200/_river/report_jdbc_river‘
elasticsearch使用river同步mysql資料