To resolve high query latency during interactive big data analytics on Hadoop, synchronize the data to an Alibaba Cloud Elasticsearch cluster for analysis. Elasticsearch can return results in seconds for various query types, especially for an ad hoc query. This topic describes how to use the Data Integration service of DataWorks to quickly synchronize large volumes of data to an Alibaba Cloud Elasticsearch cluster.
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 an Alibaba Cloud Elasticsearch cluster and enable its auto-indexing feature. For more information, see Create an Alibaba Cloud Elasticsearch cluster and Configure YML parameters.
NoteYou can synchronize data only to an Alibaba Cloud Elasticsearch cluster. Self-managed Elasticsearch clusters are not supported.
-
A DataWorks workspace is created. For more information, see Create a workspace.
-
You have a Hadoop cluster that contains data.
-
The Hadoop cluster, Alibaba Cloud Elasticsearch cluster, and DataWorks workspace must be in the same region.
-
The Hadoop cluster, Alibaba Cloud Elasticsearch cluster, and DataWorks workspace must be in the same time zone. Otherwise, time zone differences can cause discrepancies between the source and synchronized 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: Create an exclusive resource group
To ensure fast and stable data transmission, purchase an exclusive resource group for Data Integration and associate it with a workspace and Virtual Private Cloud (VPC).
-
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, click .
-
On the DataWorks Exclusive Resources (Subscription) purchase page, set Exclusive Resource Type to exclusive resource group for Data Integration, enter a name for the resource group, and then click Buy Now.
For more information, see Step 1: Purchase a resource group.
-
Find the created exclusive resource group and click Network Settings in the Actions column to associate the resource group 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 as an example. For information about how to synchronize data over the internet, see Configure an IP address whitelist.
The exclusive resource group must be connected to the VPCs of both the Hadoop and Elasticsearch clusters to allow data synchronization between them. Therefore, you must associate the exclusive resource group with the Virtual Private Cloud (VPC), Zone, and VSwitch of both the Hadoop cluster and the Elasticsearch cluster. To view the VPC, zone, and vSwitch of the Elasticsearch cluster, see View the basic information of an Elasticsearch cluster.
ImportantAfter you associate the exclusive resource group with a VPC, you must add the vSwitch CIDR Block to the VPC private access whitelists of the Hadoop and Elasticsearch clusters. For more information, see Configure a public or private IP address whitelist 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 created exclusive resource group and click Associate Workspace in the Actions column to associate the resource group with the destination workspace.
For more information, see Step 2: Associate a workspace with the resource group.
Step 2: Add data sources
-
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 an HDFS data source.
-
On the Data Sources page, click Add Data Source.
-
In the Add Data Source dialog box, search for and select HDFS.
-
On the Add HDFS Data Source page, configure the data source parameters.
For more information, see Configure an HDFS data source.
-
Click Test Connectivity. If Connected is displayed, the resource group is connected to the data source.
-
Click Complete.
-
-
Similarly, add an Elasticsearch data source. For more information, see Elasticsearch data source.
Step 3: Run a batch synchronization task
A batch synchronization task runs on an exclusive resource group. The resource group obtains data from the data source in Data Integration and writes the data to the destination Elasticsearch cluster.
-
You can configure a batch synchronization task in wizard mode or script mode. This topic uses the wizard mode as an example. For information about how to use the script mode, see Configure a 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.
-
Log on to the DataWorks console.
-
In the left-side navigation pane, click Workspace.
-
In the Actions column for the destination workspace, choose .
-
-
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 resources.
-
In the Source section, set Source to HDFS and Data Source Name to the name of the HDFS data source that you want to synchronize.
-
In the Resource Group section, select the exclusive resource group.
-
In the Destination section, set Destination to Elasticsearch and Data Source Name to the name of the Elasticsearch data source.
-
-
Click Next.
-
Configure the task.
-
In the Source section, select the table that you want to synchronize.
-
In the Destination section, configure the parameters.
-
In the Field Mapping section, configure mappings between Source Column and Target Column.
-
In the Channel Control section, configure the channel parameters.
For more information, see Configure a batch 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 parameters as required. For more information about the parameters, see Scheduling configuration.
-
In the toolbar of the node configuration tab, click the Save icon.
-
In the toolbar of the node configuration tab, click the Commit icon.
If you configured scheduling properties, the task runs periodically. You can also click the Run icon in the toolbar to run the task immediately.
A
Shell run successfully!message in the run log indicates that the task completed successfully.
-
Step 4: Verify the result
-
Log on to the Kibana console of your destination Alibaba Cloud Elasticsearch cluster.
For more information, see Log on to the Kibana console.
-
In the left-side navigation pane, click Dev Tools.
-
In the Console, run the following command to view the synchronized data.
POST /hive_esdoc_good_sale/_search?pretty { "query": { "match_all": {}} }Notehive_esdoc_good_saleis the value you specified for theindexparameter in the data synchronization script.If the data was synchronized successfully, a result similar to the following is returned.
{ "took" : 6, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 4, "max_score" : 1.0, "hits" : [ { "_index" : "hive_esdoc_good_sale", "_type" : "_doc", "_id" : "2018-08-21 00:00:00", "_score" : 1.0, "_source" : { "trans_num" : 3, "click_cnt" : 7, "category" : "Outerwear", "buyer_id" : "lilei", "trans_amount" : 500.6, "brand" : "Brand A" } }, { "_index" : "hive_esdoc_good_sale", "_type" : "_doc", "_id" : "2018-08-23 00:00:00", "_score" : 1.0, "_source" : { "trans_num" : 5, "click_cnt" : 4, "category" : "Outerwear", "buyer_id" : "jimmy", "trans_amount" : 100.2, "brand" : "Brand E" } }, { "_index" : "hive_esdoc_good_sale", "_type" : "_doc", "_id" : "2018-08-22 00:00:00", "_score" : 1.0, "_source" : { "trans_num" : 2, "click_cnt" : 3 } } ] } }