elasticsearch使用river同步mysql資料

來源:互聯網
上載者:User

標籤: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資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.