自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

DTS數(shù)據傳輸同步MySQL至Elasticsearch實戰(zhàn)

數(shù)據庫 MySQL
本章節(jié)通過RDS MySQL中的生產數(shù)據實時同步到阿里云Elasticsearch中進行搜索查詢,通過數(shù)據傳輸服務DTS(Data Transmission Service)進行數(shù)據同步操作。

概述

數(shù)據傳輸服務DTS(Data Transmission Service)是阿里云提供的實時數(shù)據流服務,支持關系型數(shù)據庫(RDBMS)、非關系型的數(shù)據庫(NoSQL)、數(shù)據多維分析(OLAP)等數(shù)據源間的數(shù)據交互,集數(shù)據同步、遷移、訂閱、集成、加工于一體,助您構建安全、可擴展、高可用的數(shù)據架構。其底層基礎設施采用阿里雙11異地多活架構,為數(shù)千下游應用提供實時數(shù)據流,已在線上穩(wěn)定運行7年之久。

本章節(jié)通過RDS MySQL中的生產數(shù)據實時同步到阿里云Elasticsearch中進行搜索查詢,通過數(shù)據傳輸服務DTS(Data Transmission Service)進行數(shù)據同步操作。

前提條件

  • 已創(chuàng)建源RDS MySQL實例,詳情請參見快速創(chuàng)建RDS MySQL實例。
  • 已創(chuàng)建目標Elasticsearch實例,詳情請參見創(chuàng)建阿里云Elasticsearch實例。
  • 目標Elasticsearch實例的存儲空間須大于源RDS MySQL實例占用的存儲空間。

概念對應關系

圖片圖片

創(chuàng)建DTS實例

創(chuàng)建同步任務

圖片圖片


選擇需要同步的RDS MySQL表

圖片圖片

任務同步進展

第一次同步是全量同步第一次同步是全量同步


驗證數(shù)據同步結果

默認情況下,您還需要同時選中庫表結構同步和全量同步。預檢查完成后,DTS會將源實例中待同步對象的全量數(shù)據在目標集群中初始化,作為后續(xù)增量同步數(shù)據的基線數(shù)據。

待全量同步完成,增量同步進行中時,您即可在Elasticsearch中查看同步成功的數(shù)據。

圖片圖片

數(shù)據同步完成后,我們通過Kibana訪問實例進行數(shù)據驗證。

圖片圖片

  1. 在Kibana區(qū)域,單擊公網入口
  2. 在登錄頁面輸入賬號和密碼,單擊登錄
  3. 單擊Kibana頁面左上角的image圖標,選擇Management > 開發(fā)工具(Dev Tools)。
  4. 在Console頁簽下,執(zhí)行如下命令訪問Elasticsearch實例

全局查詢

GET /mall_category/_search

搜索成功后,返回結果如下,以下結果表示全量同步到Elasticsearch成功。

{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1041,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "mall_category",
        "_type" : "mall_category",
        "_id" : "2513",
        "_score" : 1.0,
        "_source" : {
          "id" : 2513,
          "name" : "有商品無法刪2",
          "parent_id" : 2512,
          "is_show" : 1,
          "sort_order" : 0,
          "create_time" : 1679537485,
          "update_time" : 1679537485,
          "delete_time" : 1679542632
        }
      },
      ....
      {
        "_index" : "mall_category",
        "_type" : "mall_category",
        "_id" : "1310",
        "_score" : 1.0,
        "_source" : {
          "id" : 1310,
          "name" : "發(fā)飾",
          "parent_id" : 1258,
          "is_show" : 1,
          "sort_order" : 0,
          "create_time" : 0,
          "update_time" : 0,
          "delete_time" : 0
        }
      }
    ]
  }
}

條件查詢

GET /mall_category/_search
{
  "query": {
    "match": {
      "name": "有商品無法刪2"
    }
  }
}

搜索成功后,返回結果如下:

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 59,
      "relation" : "eq"
    },
    "max_score" : 21.80254,
    "hits" : [
      {
        "_index" : "mall_category",
        "_type" : "mall_category",
        "_id" : "2513",
        "_score" : 21.80254,
        "_source" : {
          "id" : 2513,
          "name" : "有商品無法刪2",
          "parent_id" : 2512,
          "is_show" : 1,
          "sort_order" : 0,
          "create_time" : 1679537485,
          "update_time" : 1679537485,
          "delete_time" : 1679542632
        }
      },
      {
        "_index" : "mall_category",
        "_type" : "mall_category",
        "_id" : "2512",
        "_score" : 16.643557,
        "_source" : {
          "id" : 2512,
          "name" : "有商品無法刪1",
          "parent_id" : 2511,
          "is_show" : 1,
          "image_url" : "",
          "sort_order" : 0,
          "create_time" : 1679537458,
          "update_time" : 1679537458,
          "delete_time" : 1679554114
        }
      },
      {
        "_index" : "mall_category",
        "_type" : "mall_category",
        "_id" : "2511",
        "_score" : 15.356989,
        "_source" : {
          "id" : 2511,
          "name" : "測試有商品無法刪",
          "parent_id" : 0,
          "is_show" : 1,
          "image_url" : "",
          "sort_order" : 0,
          "create_time" : 1679537448,
          "update_time" : 1679537448,
          "delete_time" : 1679554191
        }
      },
      {
        "_index" : "mall_category",
        "_type" : "mall_category",
        "_id" : "2508",
        "_score" : 4.6345234,
        "_source" : {
          "id" : 2508,
          "name" : "無糖 代糖",
          "parent_id" : 0,
          "is_show" : 1,
          "sort_order" : 0,
          "create_time" : 1679534815,
          "update_time" : 1679534815,
          "delete_time" : 1679642540
        }
      },
      {
        "_index" : "mall_category",
        "_type" : "mall_category",
        "_id" : "2045",
        "_score" : 4.5389233,
        "_source" : {
          "id" : 2045,
          "name" : "無痕塑身",
          "parent_id" : 1350,
          "is_show" : 1,
          "sort_order" : 0,
          "create_time" : 0,
          "update_time" : 0,
          "delete_time" : 0
        }
      },
      {
        "_index" : "mall_category",
        "_type" : "mall_category",
        "_id" : "2240",
        "_score" : 4.3105736,
        "_source" : {
          "id" : 2240,
          "name" : "無人機",
          "parent_id" : 1363,
          "is_show" : 1,
          "sort_order" : 0,
          "create_time" : 0,
          "update_time" : 0,
          "delete_time" : 0
        }
      }
    ]
  }
}

精準查詢

GET /mall_category/_search
{
  "query": {
    "match_phrase": {
      "name": "有商品無法刪2"
    }
  }
}

搜索成功后,返回結果如下:

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 21.80254,
    "hits" : [
      {
        "_index" : "mall_category",
        "_type" : "mall_category",
        "_id" : "2513",
        "_score" : 21.80254,
        "_source" : {
          "id" : 2513,
          "name" : "有商品無法刪2",
          "parent_id" : 2512,
          "is_show" : 1,
          "sort_order" : 0,
          "create_time" : 1679537485,
          "update_time" : 1679537485,
          "delete_time" : 1679542632
        }
      }
    ]
  }
}

增量同步

在MySQL中插入一條數(shù)據,在Elasticsearch中查看增量數(shù)據同步結果。例如通過以下SQL語句插入一條數(shù)據。

INSERT INTO `mall_category`
( `name`, `parent_id`, `is_show`, `image_url`, `sort_order`,
 `create_time`, `update_time`, `delete_time` )
VALUES
 ( '開源技術小棧', 1361, 1, 
 'https://img.tinywan.com/shop/img/2024-12/3a5cbd823.png', 0, 0, 0, 0 );

這里通過精準查詢方式查詢

GET /mall_category/_search
{
  "query": {
    "match_phrase": {
      "name": "開源技術小棧"
    }
  }
}

在Elasticsearch中查看結果,預期結果如下:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 21.59761,
    "hits" : [
      {
        "_index" : "mall_category",
        "_type" : "mall_category",
        "_id" : "2537",
        "_score" : 21.59761,
        "_source" : {
          "update_time" : 0,
          "delete_time" : 0,
          "create_time" : 0,
          "image_url" : "https://img.tinywan.com/shop/img/2024-12/3a5cbd823.png",
          "parent_id" : 1361,
          "name" : "開源技術小棧",
          "id" : 2537,
          "sort_order" : 0,
          "is_show" : 1
        }
      }
    ]
  }
}

圖片圖片


責任編輯:武曉燕 來源: 開源技術小棧
相關推薦

2023-04-12 16:20:00

同步數(shù)據異步數(shù)據傳輸

2021-01-06 08:32:30

DTS數(shù)據傳輸數(shù)據庫

2020-06-12 07:50:15

大數(shù)據

2024-10-18 11:39:55

MySQL數(shù)據檢索

2010-04-07 14:54:38

2020-08-13 08:34:10

MySQL數(shù)據DTS

2019-05-29 09:38:44

MySQL字符編碼數(shù)據庫

2010-07-13 15:55:12

FTP數(shù)據傳輸模式

2013-11-26 15:51:45

Android編程藍牙數(shù)據傳輸

2015-10-14 09:44:55

TCP網絡協(xié)議數(shù)據傳輸

2009-12-08 11:17:41

WCF雙向通信

2009-07-07 16:46:33

數(shù)據傳輸銅纜結構

2021-12-14 11:01:44

TCPUDP網絡協(xié)議

2021-06-09 11:28:06

加密數(shù)據Jsencrypt

2019-09-06 09:11:36

以太網數(shù)據二層交換

2017-05-04 12:48:18

WOT網易NDC

2022-03-30 15:06:25

數(shù)據傳輸Harmony源碼分析

2011-03-02 11:23:48

2021-10-08 08:37:38

數(shù)據傳輸數(shù)據調用網絡協(xié)議

2018-10-24 17:57:55

MySQL
點贊
收藏

51CTO技術棧公眾號