To retrieve information, run multi-dimensional queries, or perform statistical analysis on large datasets in MaxCompute (ODPS), use Alibaba Cloud Elasticsearch. This topic describes how to use Data Integration in DataWorks to synchronize large volumes of data from MaxCompute to an Alibaba Cloud Elasticsearch cluster in minutes.
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
-
Create a MaxCompute project. For more information, see Create a MaxCompute project.
-
Create an Alibaba Cloud Elasticsearch cluster and enable its auto-indexing feature. For more information, see Create an Alibaba Cloud Elasticsearch cluster and Configure the YML file.
-
Create a DataWorks workspace. For more information, see Create a workspace.
-
You can synchronize data only to an Alibaba Cloud Elasticsearch cluster. Self-managed Elasticsearch clusters are not supported.
-
The MaxCompute project, Alibaba Cloud Elasticsearch cluster, and DataWorks workspace must be in the same region.
-
The Alibaba Cloud Elasticsearch cluster, MaxCompute project, and DataWorks workspace must be in the same time zone. Otherwise, time zone discrepancies may occur when you synchronize time-related data.
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
Create a MaxCompute table and import test data into the table. For more information, see Create a table and Import data.
This topic uses the following table schema and sample data:
-
Table schema
The table contains 7 fields and 1 partition field. The fields are defined as follows:
create_time(string, primary key)category(string)brand(string)buyer_id(string)trans_num(bigint)trans_amount(double)click_cnt(bigint)
The partition field is
pt(bigint). -
Sample data
The source table contains the following fields:
create_time: transaction date, for example, 2020/6/1category: product category, for example, Outerwear, Fresh Food, Electronics, Bathroombrand: brand name, for example, Brand A to Brand Gbuyer_id: buyer ID, for example, user1 to user13trans_num: number of transactionstrans_amount: transaction amountclick_cnt: number of clickspt: partition field, with a value of 1
Step 2: Purchase and configure an exclusive resource group
Purchase an exclusive resource group for Data Integration and associate it with a VPC and a workspace. An exclusive resource group ensures 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 Groups.
-
On the Exclusive Resource Group tab, choose .
-
On the DataWorks Exclusive Resources (Subscription) purchase page, set Exclusive Resource Type to Exclusive Resources for Data Integration, enter a name for the resource group, and click Buy Now.
For more information about the configuration, see Step 1: Purchase a resource group.
-
Find the exclusive resource group you created and click Network Settings in the Actions column to associate it with a VPC. For more information, see Bind a VPC.
NoteThis topic uses an exclusive resource group for Data Integration to synchronize data over a VPC. For information about how to synchronize data over the internet, see Configure an allowlist.
To enable data synchronization, the exclusive resource group must be connected to the VPC where the Alibaba Cloud Elasticsearch cluster resides. Therefore, you must associate the exclusive resource group with the Virtual Private Cloud (VPC), Zone, and VSwitch of your Alibaba Cloud Elasticsearch cluster. To view this information, see View the basic information of an Elasticsearch cluster.
ImportantAfter associating the exclusive resource group with the VPC, you must add the vSwitch CIDR Block to the VPC private IP allowlist of the Alibaba Cloud Elasticsearch cluster. For more information, see Configure a public or private IP address allowlist for an Elasticsearch cluster.
-
In the upper-left corner of the page, click the back icon to return to the Resource List page.
-
Find the exclusive resource group you created and click Associate Workspace in the Actions column to associate it with the target workspace.
For more information, see Step 2: Associate a workspace.
Step 3: Add data sources
Add MaxCompute and Alibaba Cloud Elasticsearch as data sources in Data Integration.
-
Go to the Data Integration page.
-
Log on to the DataWorks console .
-
In the left-side navigation pane, click Workspace.
-
Find the target workspace and choose in the Actions column.
-
-
In the left-side navigation pane, click Data Source.
-
Add a MaxCompute data source.
-
On the Data Sources page, click Add Data Source.
-
On the Add Data Source page, find and select the MaxCompute data source type.
-
In the Add MaxCompute data source dialog box, configure the parameters in the Basic Information section.
For more information, see Configure a MaxCompute data source.
-
In the Connection Configuration section, click Test Connectivity. A status of Connected indicates that the connection is successful.
-
Click Complete.
-
-
Follow the same procedure to add an Elasticsearch data source. For more information, see Configure an Elasticsearch data source.
Step 4: Configure and run a batch synchronization task
A batch synchronization task runs using the exclusive resource group. The resource group retrieves data from the data source in Data Integration and writes the data to the Alibaba Cloud Elasticsearch cluster.
-
You can configure a batch synchronization task in wizard mode or script mode. This topic demonstrates the wizard mode. For more information, see Configure a synchronization task in script mode and Elasticsearch Writer.
-
The following steps are performed on the legacy Data Development (DataStudio) page.
-
Go to the Data development page in DataWorks.
-
Log on to the DataWorks console .
-
In the left-side navigation pane, click Workspace.
-
Find the target workspace and choose in the Actions column.
-
-
Create an offline synchronization node.
-
On the Data Development (
) tab, choose . -
Right-click the workflow that you created and choose .
-
In the Create Node dialog box, enter a name for the node and click OK.
-
-
Configure the network and resource group.
-
In the Source section, set Source to MaxCompute(ODPS) and select your source data source under Data Source Name.
-
In the Resource Group section, select the exclusive resource group.
-
In the Destination section, set Destination to Elasticsearch and select your destination data source under Data Source Name.
-
-
Click Next step.
-
Configure the task.
-
In the Source section, select the source table.
-
In the Destination section, configure the parameters for the destination.
-
In the Field Mapping section, map the Source Column to the Target Column.
-
In the Channel Control section, configure the channel parameters.
For more information about the configuration, see Configure a synchronization 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 as needed. For more information about the parameters, see Scheduling configuration.
-
In the upper-right corner of the node area, click the Save icon to save the task.
-
In the upper-right corner of the node area, click the Commit icon.
If you configure scheduling properties for the task, the task runs automatically at scheduled intervals. You can also click the Run icon in the upper-right corner of the node area to run the task immediately.
The message
Shell run successfully!in the run log indicates that the task ran successfully. A sample of the task run log is as follows:2023-10-31 16:52:35 INFO Exit code of the Shell command 0 2023-10-31 16:52:35 INFO --- Invocation of Shell command completed --- 2023-10-31 16:52:35 INFO Shell run successfully! 2023-10-31 16:52:35 INFO Current task status: FINISH 2023-10-31 16:52:35 INFO Cost time is: 33.106s
-
Step 5: Verify the data synchronization result
In the Kibana console, view the synchronized data and run queries.
-
Log on to the Kibana console of the target Alibaba Cloud Elasticsearch cluster.
For more information, see Log on to the Kibana console.
-
In the upper-left corner of the Kibana page, click the
icon and select Dev Tools. -
In the Console, run the following command to view the synchronized data.
POST /odps_index/_search?pretty { "query": { "match_all": {}} }Noteodps_indexis the value of theindexfield that you set in the data synchronization script.A successful synchronization returns the following result.
POST /odps_index/_search?pretty { "query": { "match_all": {}} } POST /odps_index/_search?pretty { "query": { "match_all": {} }, "_source": ["category", "brand"] } POST /odps_index/_search?pretty { "query": { "match": {"category":"生鲜"} } } POST /odps_index/_search?pretty { "query": { "match_all": {} }, "sort": { "trans_num": { "order": "desc" } } } --- Response --- { "took" : 2, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 13, "max_score" : null, "hits" : [ { "_index" : "odps_index", "_type" : "_doc", "_id" : "2020/6/7 8:00", "_score" : null, "_source" : { "trans_num" : 88, "click_cnt" : 80, "category" : "外套", "buyer_id" : "user7", "trans_amount" : 150.0, "brand" : "品牌E" }, "sort" : [ 88 ] }, { "_index" : "odps_index", "_type" : "_doc", "_id" : "2020/6/11 8:00", "_score" : null, "_source" : { "trans_num" : 22, "click_cnt" : 70, "category" : "卫浴", "buyer_id" : "user11", "trans_amount" : 4500.0, "brand" : "品牌G" }, "sort" : [ 22 ] } ] } } -
Run the following command to search for the
categoryandbrandfields in the document.POST /odps_index/_search?pretty { "query": { "match_all": {} }, "_source": ["category", "brand"] } -
Run the following command to search for documents where
categoryisfresh food.POST /odps_index/_search?pretty { "query": { "match": {"category":"生鲜"} } } -
Run the following command to sort the documents by the
trans_numfield.POST /odps_index/_search?pretty { "query": { "match_all": {} }, "sort": { "trans_num": { "order": "desc" } } }For more commands and access methods, see the Elastic.co Help Center.