If your business data is stored in PolarDB for Xscale (PolarDB-X) and you want to perform full-text searches and semantic analytics on the data, you can use the Data Integration service of DataWorks to synchronize the data to Alibaba Cloud Elasticsearch. The data can be synchronized within minutes or a longer period of time. This topic describes how to use the Data Integration service to synchronize data from PolarDB-X to Alibaba Cloud Elasticsearch in offline mode.
Background information
DataWorks is an end-to-end big data development and governance platform based on big data compute engines. DataWorks provides features such as data development, task scheduling, and data management. You can create synchronization tasks in DataWorks to rapidly synchronize data from various data sources to Alibaba Cloud Elasticsearch.
Prerequisites
Note
You can synchronize data only to Alibaba Cloud Elasticsearch. Self-managed Elasticsearch is not supported.
The PolarDB-X instance, Elasticsearch cluster, and DataWorks workspace must reside in the same region.
The PolarDB-X instance, Elasticsearch cluster, and DataWorks workspace must be in the same time zone. Otherwise, if you synchronize time-related data, the data in the source and the data in the destination after the synchronization may have a time zone difference.
Procedure
Step 1: Prepare source data
Insert data into a table in the PolarDB-X instance.
For more information, see Basic SQL operations. The following figure shows the test data that is used in this example.
Step 2: Create an exclusive resource group for Data Integration
Create an exclusive resource group for Data Integration, and associate the resource group with a virtual private cloud (VPC) and the created workspace. Exclusive resource groups ensure fast and stable data transmission.
Log on to the DataWorks console.
In the top navigation bar, select a region. In the left-side navigation pane, click Resource Group.
On the Exclusive Resource Groups tab of the Resource Groups page, click Create Resource Group for Data Integration of Old Version.
On the DataWorks Exclusive Resources page, set Type to Exclusive Resource Groups for Data Integration, configure Resource Group Name, and then click Buy Now. On the page that appears, click Pay.
For more information, see Create an exclusive resource group for Data Integration.
On the Exclusive Resource Groups tab, find the created resource group and click Network Settings in the Actions column to associate the resource group with a VPC. For more information, see Associate the exclusive resource group for Data Integration with a VPC.
Note
In this example, an exclusive resource group for Data Integration is used to synchronize data over a VPC. For information about how to use an exclusive resource group for Data Integration to synchronize data over the Internet, see Configure an IP address whitelist.
The exclusive resource group must be connected to the VPC where the PolarDB-X instance resides and the VPC where the Elasticsearch cluster resides. This way, data can be synchronized based on the exclusive resource group. Therefore, you must associate the exclusive resource group with the VPC, zone, and vSwitch of the PolarDB-X instance and with those of the Elasticsearch cluster. For information about how to view the VPC where the Elasticsearch cluster resides, see View the basic information of a cluster.
Click the back icon in the upper-left corner of the page to return to the Resource Groups page.
On the Exclusive Resource Groups tab, find the resource group and click Associate Workspace in the Actions column to associate the resource group with the created workspace.
For more information, see Associate the exclusive resource group for Data Integration with a workspace.
Step 3: Add data sources
Add the PolarDB-X instance and Elasticsearch cluster to Data Integration as data sources.
Go to the Data Integration page.
Log on to the DataWorks console.
In the left-side navigation pane, click Workspace.
Find the workspace and choose in the Actions column.
In the left-side navigation pane of the Data Integration page, click Data source.
Add a PolarDB-X data source.
On the Data Sources page, click Add Data Source.
In the Add Data Source dialog box, search for and select DRDS.
In the Add DRDS Data Source dialog box, configure the parameters and test connectivity. After the connectivity test is passed, click Complete.
For more information, see Add a PolarDB-X data source.
Add an Elasticsearch data source in the same way. For more information, see Add an Elasticsearch data source.
Step 4: Configure and run a batch synchronization task
The exclusive resource group is used to run the batch synchronization task. The resource group obtains data from the source and writes the data to the Elasticsearch cluster.
Go to the DataStudio page of DataWorks.
Log on to the DataWorks console.
In the left-side navigation pane, click Workspace.
Find the workspace and choose in the Actions column.
Create a batch synchronization task.
In the left-side navigation pane, choose to create a workflow.
Right-click the name of the newly created workflow and choose .
In the Create Node dialog box, configure the Name parameter and click Confirm.
Configure the network and resources.
For the source part, set Source to DRDS and Data Source Name to the name of the added PolarDB-X data source.
For the resource group part, select the created exclusive resource group.
For the destination part, set Destination to Elasticsearch and Data Source Name to the name of the added Elasticsearch data source.
Click Next.
Configure the task.
In the Source section, select the table whose data you want to synchronize.
In the Destination section, configure the parameters.
In the Field Mapping section, configure mappings between source fields and destination fields.
In this example, the default source fields are used. You need to only change destination fields. Click the
icon to the right of destination fields. In the dialog box that appears, enter the following information:
{"name":"Name","type":"text"}
{"name":"Platform","type":"text"}
{"name":"Year_of_Release","type":"date"}
{"name":"Genre","type":"text"}
{"name":"Publisher","type":"text"}
{"name":"na_Sales","type":"float"}
{"name":"EU_Sales","type":"float"}
{"name":"JP_Sales","type":"float"}
{"name":"Other_Sales","type":"float"}
{"name":"Global_Sales","type":"float"}
{"name":"Critic_Score","type":"long"}
{"name":"Critic_Count","type":"long"}
{"name":"User_Score","type":"float"}
{"name":"User_Count","type":"long"}
{"name":"Developer","type":"text"}
{"name":"Rating","type":"text"}
In the Channel Control section, configure the parameters.
For more information, see Configure a batch synchronization task by using the codeless UI.
Run the task.
(Optional) Configure scheduling properties for the task. In the right-side navigation pane, click Properties. On the Properties tab, configure the parameters based on your business requirements. For more information about the parameters, see Scheduling configuration.
In the upper-left corner, click the Save icon to save the task.
In the upper-left corner, click the Submit icon to submit the task.
If you configure scheduling properties for the task, the task is automatically run on a regular basis. You can also click the Run icon in the upper-left corner to run the task immediately.
If Shell run successfully!
is displayed in operational logs, the task runs successfully.
Step 5: View the synchronized data
Log on to the Kibana console of the Elasticsearch cluster.
In the left-side navigation pane, click Dev Tools.
On the Console tab of the page that appears, run the following command to query the volume of data in the Elasticsearch cluster.
Note
You can compare the queried data volume with the volume of data in the source to check whether all data is synchronized.
GET drdstest/_search
{
"query": {
"match_all": {}
}
}
If the command is successfully run, the result shown in the following figure is returned.
Run the following command to search for data by using a specific field:
GET drdstest/_search
{
"query": {
"term": {
"Publisher.keyword": {
"value": "Nintendo"
}
}
}
}
If the command is successfully run, the result shown in the following figure is returned.