You can use the snapshots that are stored in Object Storage Service (OSS) to migrate data from a self-managed Elasticsearch cluster to an Alibaba Cloud Elasticsearch cluster. To migrate data, call the snapshot operation to create a snapshot for the self-managed Elasticsearch cluster. Then, store the snapshot in OSS and restore data from the snapshot to your Alibaba Cloud Elasticsearch cluster. This topic describes the detailed procedure.
Background information
Procedure
Preparations
Step 1: Install the elasticsearch-repository-oss plug-in
Step 2: Create a snapshot repository for the self-managed Elasticsearch cluster
Connect to the ECS instance that hosts the self-managed Elasticsearch cluster and run the following command to create a snapshot repository:
curl -H "Content-Type: application/json" -XPUT localhost:9200/_snapshot/es_backup -d' {"type": "oss", "settings": { "endpoint": "http://oss-cn-hangzhou-internal.aliyuncs.com", "access_key_id": "your_accesskeyid", "secret_access_key":"your_accesskeysecret", "bucket": "es-backup-es", "compress": true }}'
Parameter | Description |
---|---|
es_backup |
The name of the repository, which can be customized. |
type |
The type of the repository. Set the value to oss .
|
endpoint |
The endpoint of your OSS bucket. For more information, see Regions and endpoints.
Note If the ECS instance that hosts the self-managed Elasticsearch cluster resides in the
same region as your OSS bucket, use the internal endpoint of the OSS bucket. Otherwise,
use the public endpoint.
|
access_key_id |
The AccessKey ID of the Alibaba Cloud account that is used to create the OSS bucket. For more information about how to obtain the AccessKey ID, see How can I obtain an AccessKey ID and AccessKey secret? |
secret_access_key |
The AccessKey secret of the Alibaba Cloud account that is used to create the OSS bucket. For more information about how to obtain the AccessKey secret, see How can I obtain an AccessKey ID and AccessKey secret? |
bucket |
The name of your OSS bucket. |
compress |
Specifies whether to enable compression. |
If the repository is created, "acknowledge":true
is returned.
Step 3: Create a snapshot for specific indexes
.kibana
, .security
, or .monitoring
, you can specify the indexes that you want to back up.
curl -H "Content-Type: application/json" -XPUT localhost:9200/_snapshot/es_backup/snapshot_1? pretty -d'
{
"indices": "index1,index2"
}'
index1
and index2
indicate the names of the indexes that you want to back up. If the snapshot is created,
"accepted" : true
is returned.
Step 4: Create the same snapshot repository for the Alibaba Cloud Elasticsearch cluster
Step 5: Restore data to the Alibaba Cloud Elasticsearch cluster from the created snapshot
.
) from the created snapshot. Follow the instructions in the "Step 4: Create the same snapshot repository for the Alibaba Cloud Elasticsearch cluster" section to perform the restoration. POST _snapshot/es_backup/snapshot_1/_restore
{"indices":"*,-.monitoring*,-.security_audit*","ignore_unavailable":"true"}
If the command is successfully executed, "accepted" : true
is returned.
POST _snapshot/es_backup/snapshot_1/_restore
{
"indices":"index1",
"rename_pattern": "index(.+)",
"rename_replacement": "restored_index_$1"
}
Step 6: View restoration results
- View the restored indexes
GET /_cat/indices?v
- View the data in the restored indexes
GET /index1/_search
If the command is successfully executed, the following result is returned:{ "took" : 2, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 1.0, "hits" : [ { "_index" : "index1", "_type" : "_doc", "_id" : "1", "_score" : 1.0, "_source" : { "productName" : "testpro", "annual_rate" : "3.22%", "describe" : "testpro" } } ] } }