If you need to search and analyze data in ApsaraDB RDS for SQL Server, you can use Alibaba Cloud Elasticsearch. This topic describes how to use the Data Integration service of DataWorks to quickly sync data offline to Alibaba Cloud Elasticsearch.
Background
DataWorks is an end-to-end big data development and governance platform built on big data engines. It integrates features such as data development, task scheduling, and data management. You can use synchronization tasks in DataWorks to quickly synchronize data from various data sources to Alibaba Cloud Elasticsearch.
-
Supported data sources include:
-
Alibaba Cloud databases (MySQL, PostgreSQL, SQL Server, MongoDB, and HBase)
-
Alibaba Cloud PolarDB-X (upgraded from DRDS)
-
Alibaba Cloud MaxCompute
-
Alibaba Cloud OSS
-
Alibaba Cloud Tablestore
-
Self-managed versions of HDFS, Oracle, FTP, DB2, and other supported database types
-
-
Scenarios:
-
Offline synchronization of big data to Alibaba Cloud Elasticsearch. You can synchronize an entire database or all data in a specific table. For more information, see Offline synchronization of an entire MySQL database to Elasticsearch.
-
Real-time synchronization of big data to Alibaba Cloud Elasticsearch. This method supports both full and incremental synchronization. For more information, see Real-time synchronization of an entire MySQL database to Elasticsearch.
-
Prerequisites
-
You have created an ApsaraDB RDS for SQL Server instance. This topic uses an ApsaraDB RDS for SQL Server 2019 Standard Edition instance as an example. For more information, see Quickly create and use an ApsaraDB RDS for SQL Server instance.
-
You have created an Alibaba Cloud Elasticsearch instance and enabled the automatic index creation feature. For more information, see Create an Alibaba Cloud Elasticsearch instance and Configure YML parameters.
-
You have created a DataWorks workspace. For more information, see Create a workspace.
-
You can synchronize data only to Alibaba Cloud Elasticsearch instances. Self-managed Elasticsearch instances are not supported.
-
The ApsaraDB RDS for SQL Server instance, Alibaba Cloud Elasticsearch instance, and DataWorks workspace must be in the same region.
-
The ApsaraDB RDS for SQL Server instance, Alibaba Cloud Elasticsearch instance, and DataWorks workspace must be in the same time zone. Otherwise, a time zone mismatch may cause offsets in time-related data after syncing.
Billing
-
For information about the fees for an Alibaba Cloud Elasticsearch instance, see Elasticsearch billable items.
-
For information about the fees for a Data Integration resource group, see Resource group fees.
Procedure
Step 1: Prepare the source data
The following sample data is used in the ApsaraDB RDS for SQL Server instance.
The data in this topic is for testing only. Do not use it in a production environment.
-
Create a table
CREATE TABLE students( id INT, name VARCHAR(20), age INT ) -
Insert data
INSERT INTO [students]( [id] , [name] , [age] )values('1', 'Xiaoming','21'); INSERT INTO [students]( [id] , [name] , [age] )values('2', 'Xiaozhang','22'); INSERT INTO [students]( [id] , [name] , [age] )values('3', 'Xiaowang','23');
Step 2: Purchase and configure an exclusive resource group
Purchase an exclusive resource group for Data Integration and attach a Virtual Private Cloud (VPC) and a workspace. An exclusive resource group ensures fast and stable data transmission.
-
Log on to the DataWorks console .
-
In the top menu bar, select a region. In the left-side navigation pane, click Resource Groups.
-
On the Exclusive Resource Group tab, click .
-
On the DataWorks Exclusive Resource (Subscription) purchase page, set Exclusive Resource Type to Exclusive Resource for Data Integration, enter a name for the resource group, and then click Buy Now.
For more configuration information, see Step 1: Purchase a resource group.
-
In the Actions column of the newly created exclusive resource group, click Network Settings to attach a VPC to the resource group. For more information, see Attach a VPC.
NoteThis topic uses an exclusive resource group for Data Integration to synchronize data over a VPC internal network as an example. For more information, see Add a whitelist.
The exclusive resource group must be able to connect to the VPCs of the ApsaraDB RDS for SQL Server and Alibaba Cloud Elasticsearch instances to synchronize data. Therefore, you must attach the Virtual Private Cloud (VPC), Zone, and VSwitch of the ApsaraDB RDS for SQL Server and Alibaba Cloud Elasticsearch instances. To view the VPC information of an instance, see Switch the vSwitch for an ApsaraDB RDS for SQL Server instance and View the basic information of an Elasticsearch instance.
ImportantAfter attaching the VPC, you must add the vSwitch CIDR Block to the private whitelists of both the ApsaraDB RDS for SQL Server and Alibaba Cloud Elasticsearch instances. For more information, see Configure a whitelist for an ApsaraDB RDS for SQL Server instance and Configure a public or private access whitelist for an Elasticsearch instance.
-
In the upper-left corner of the page, click the back icon to return to the Resource List page.
-
In the Actions column of the newly created exclusive resource group, click Attach Workspace to attach the target workspace to the resource group.
For more information, see Step 2: Attach a workspace.
Step 3: Add data sources
Add the ApsaraDB RDS for SQL Server and Alibaba Cloud Elasticsearch data sources to Data Integration in DataWorks.
-
Go to the Data Integration page in DataWorks.
-
Log on to the DataWorks console .
-
In the left-side navigation pane, click Workspace.
-
In the Actions column of the target workspace, choose .
-
-
In the left-side navigation pane, click Data Source.
-
Add an ApsaraDB RDS for SQL Server data source.
-
On the Data Sources page, click Add Data Source.
-
On the Add Data Source page, search for and select the SQLServer data source type.
-
In the Add SQL Server Data Source dialog box, configure the parameters in the Basic Information section.
For more information about the parameters, see Configure a SQLServer data source.
-
In the Connection Configuration section, click Test Connectivity. A status of Connected indicates a successful connection.
-
Click Complete.
-
-
Follow the same steps to add an Elasticsearch data source. For more information about the parameters, see Configure an Elasticsearch data source.
Step 4: Configure and run an offline sync task
The offline sync task runs on the exclusive resource group. This resource group retrieves data from the source configured in Data Integration and writes the data to Alibaba Cloud Elasticsearch.
You can configure an offline sync task in wizard mode or script mode. This topic describes how to configure the task in wizard mode. For information about script mode, see Configure a sync task in script mode and Elasticsearch Writer.
-
Go to the Data development page in DataWorks.
-
Log on to the DataWorks console .
-
In the left-side navigation pane, click Workspace.
-
In the Actions column of the target workspace, choose .
-
-
Create an offline sync task.
-
In the left-side navigation pane, click the
icon and choose to create a business flow. -
Right-click the new business flow and choose .
-
In the Create Node dialog box, enter a name for the node and click OK.
-
-
Configure the network and resources.
-
In the Source section, set Source to SQL Server and select your data source from the Data Source Name drop-down list.
-
In the Resource Group section, select the exclusive resource group.
-
In the Destination section, set Destination to Elasticsearch and select your data source from the Data Source Name drop-down list.
-
-
Click Next.
-
Configure the task.
-
In the Source section, select the table that you want to sync.
-
In the Destination section, configure the destination parameters.
-
In the Field Mapping section, map the Source Column to the Target Column. For more information about the configuration, see Configure a sync task in wizard mode.
-
In the Channel Control section, configure the channel parameters.
For detailed information about the parameters, see Configure a sync task in wizard mode.
-
-
Run the task.
-
(Optional) Configure scheduling properties for the task. In the right-side pane, click Properties and configure the scheduling parameters. For more information about the parameters, see Scheduling configuration.
-
In the upper-right corner of the node configuration tab, click the save icon to save the task.
-
In the upper-right corner of the node configuration tab, click the submit icon to submit the task.
If you configured scheduling properties for the task, the task runs periodically. You can also click the run icon in the upper-right corner of the node configuration tab to immediately run the task.
A run log containing
Shell run successfully!indicates that the task was successful.
-
Step 5: Verify the data synchronization result
-
Log on to the destination Alibaba Cloud Elasticsearch instance's Kibana console. For more information, see Log on to the Kibana console.
-
In the upper-left corner of the Kibana page, click the menu icon and choose Dev Tools.
-
In the Console, run the following command to view the synchronized data.
POST /dbo.students/_search?pretty { "query": { "match_all": {}} }NoteReplace dbo.students with the value of the index field that you specified when you configured the DataWorks data sync task.
The expected result is as follows.
{ "took" : 4, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 3, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "dbo.students", "_type" : "_doc", "_id" : "XLZFCoUBpTk7S_sKy0dj", "_score" : 1.0, "_source" : { "age" : 21, "id" : 1, "name" : "Xiaoming" } }, { "_index" : "dbo.students", "_type" : "_doc", "_id" : "XbZFCoUBpTk7S_sKy0dj", "_score" : 1.0, "_source" : { "age" : 22, "id" : 2, "name" : "Xiaozhang" } }, { "_index" : "dbo.students", "_type" : "_doc", "_id" : "XrZFCoUBpTk7S_sKy0dj", "_score" : 1.0, "_source" : { "age" : 23, "id" : 3, "name" : "Xiaowang" } } ] } }