Alibaba Cloud Elasticsearch is compatible with open-source Elasticsearch features such as Security, Machine Learning, Graph, and Application Performance Management (APM). Alibaba Cloud Elasticsearch provides capabilities such as enterprise-level access control, security monitoring and alerts, and automatic report generation. You can use Alibaba Cloud Elasticsearch to search and analyze data. You can use Data Transmission Service (DTS) to synchronize data from a user-created MySQL database that is hosted on ECS to an Elasticsearch instance.
- An Elasticsearch instance (5.5, 6.3, or 6.7 version) is created. For more information, see Create an Alibaba Cloud Elasticsearch instance.
- The version of the user-created MySQL database is 5.1, 5.5, 5.6, 5.7, or 8.0.
- DTS uses read and write resources of the source and destination databases during initial full data synchronization. This may increase the database load. If the database performance is unfavorable, the specification is low, or the data volume is large, database services may become unavailable. For example, DTS occupies a large amount of read and write resources in the following cases: a large number of slow SQL queries are performed on the source database, the tables have no primary keys, or a deadlock occurs in the destination database. Before synchronizing data, you must evaluate the performance of the source and destination databases. We recommend that you synchronize data during off-peak hours. For example, you can synchronize data when the CPU usage of the source and destination databases is less than 30%.
- DDL operations cannot be synchronized. If a DDL operation is performed on the table in the source database during data synchronization, you must perform the following steps: Remove the table from the required objects, remove the index for the table from the Elasticsearch instance, and then add the table to the required objects. For more information, see Remove an object from a data synchronization task and Add an object to a data synchronization task.
- To add columns to the table that you want to synchronize, perform the following steps: Modify the mappings of the table in the Elasticsearch instance, perform DDL operations in the source MySQL database, and then pause and start the data synchronization task.
SQL operations supported by data synchronization
INSERT, DELETE, and UPDATE operations
Data type mappings
The data types of MySQL and Elasticsearch instances do not have one-to-one correspondence. During initial schema synchronization, DTS maps the data types of the source database to the destination database. For more information, see Data type mappings for initial schema synchronization.
PreparationsCreate an account for a user-created MySQL database and configure binary logging
- Purchase a data synchronization instance. For more information, see Purchase procedure.
Note Select MySQL for the source instance and Elasticsearch for the destination instance. Select One-Way Synchronization as the synchronization topology.
- Log on to the DTS console.
- In the left-side navigation pane, click Data Synchronization.
- At the top of the Synchronization Tasks page, select the region where the destination instance resides.
- Find the data synchronization instance and click Configure Synchronization Channel in the Actions column.
- Configure the source and destination instances.
Section Parameter Description N/A Synchronization Task Name DTS automatically generates a task name. We recommend that you use an informative name for easy identification. You do not need to use a unique task name. Source Instance Details Instance Type Select User-Created Database in ECS Instance. Instance Region The region of the source instance. The region is the same as the region that you selected when you purchased the data synchronization instance. You cannot change the value of this parameter. ECS Instance ID Select the ID of the ECS instance that is connected to the user-created MySQL database. Database Type The value of this parameter is set to MySQL and cannot be changed. Port Number Enter the service port number of the user-created MySQL database. Database Account Enter the account for the user-created MySQL database.Note The account must have the REPLICATION SLAVE permission, the REPLICATION CLIENT permission, the SHOW VIEW permission, and the permission to perform SELECT operations on the required objects. Database Password Enter the password for the database account. Destination Instance Details Instance Type The value of this parameter is set to Elasticsearch and cannot be changed. Instance Region The region of the destination instance. The region is the same as the region that you selected when you purchased the data synchronization instance. You cannot change the value of this parameter. Elasticsearch Select the ID of the Elasticsearch instance. Database Account Enter the account that is used to connect to the Elasticsearch instance. The default account is elastic. Database Password Enter the password for the account.
- In the lower-right corner of the page, click Set Whitelist and Next.
Note The CIDR blocks of DTS servers are automatically added to the inbound rule of the ECS instance and the whitelist of the Elasticsearch instance. This ensures that DTS servers can connect to the source and destination instances.
- Configure the index name, the processing mode of identical index names, and the objects
to be synchronized.
Parameter Description Index Name
- Table Name
If you select Table Name, the name of the index that is created in the Elasticsearch instance is the same as the name of the table. In this example, the index name is customer.
If you select DatabaseName_TableName, the name of the index that is created in the Elasticsearch instance is <Database name>_<Table name>. In this example, the index name is dtstestdata_customer.
Processing Mode In Existed Target Table
- Pre-check and Intercept: checks whether the destination database contains indexes that have the same names
as tables in the source database. If the destination database does not contain indexes
that have the same names as tables in the source database, the precheck is passed.
Otherwise, an error is returned during precheck and the data synchronization task
cannot be started.
Note If indexes in the destination database have the same names as tables in the source database, and cannot be deleted or renamed, you can use the object name mapping feature. For more information, see Specify the name of an object in the destination instance.
- Ignore: skips the precheck for identical index names in the source and destination databases.
Warning If you select Ignore, data consistency is not guaranteed and your business may be exposed to potential risks.
- If the source and destination databases have the same mappings and the primary key of a record in the destination database is the same as that in the source database, the record remains unchanged during initial data synchronization. However, the record is overwritten during incremental data synchronization.
- If the source and destination databases have different mappings, initial data synchronization may fail. In this case, only some columns are synchronized or the data synchronization task fails.
Objects to be synchronized
Select objects from the Available section and click the icon to move the objects to the Selected section.
You can select tables and databases as the objects to be synchronized.
- Table Name
- In the Selected section, move the pointer over a table, and then click Edit. In the Edit Table dialog box that appears, configure parameters for the table in
the Elasticsearch instance, such as the index name and type name.
Parameter Description Index Name For more information, see Terms in the Elasticsearch documentation.Warning The only type of special characters that an index name and type name can contain is underscore (_). An index name and type name cannot contain the following special characters:
Type Name Filter Specify SQL conditions to filter data. Only data that meets the specified conditions is synchronized to the destination instance. For more information, see Use SQL conditions to filter data. IsPartition Select whether to set partitions. If you select Yes, you must also specify the partition key column and number of partitions. _id value
- Primary key column
Composite primary key fields are merged into one column.
- Business key
If you select a business key, you must also specify the business key column.
add param Select the column parameter and parameter value. For more information, see Mapping parameters in the Elasticsearch documentation.
- Primary key column
- In the lower-right corner of the page, click Precheck.
- Before you can start the data synchronization task, a precheck is performed. You can start the data synchronization task only after the task passes the precheck.
- If the task fails to pass the precheck, click the icon next to each failed item to view details. Troubleshoot the issues based on the causes and run the precheck again.
- Close the Precheck dialog box after the following message is displayed: The precheck is passed.
- Wait until the initial synchronization is complete and the data synchronization task
is in the Synchronizing state.
On the Synchronization Tasks page, view the status of the data synchronization task.
Check the index and data
If the data synchronization task is in the Synchronizing state, you can connect to the Elasticsearch instance and check whether the index is created and data is synchronized as expected. In this example, the Elasticsearch Head plug-in is used.