Upgrading AWS Elasticsearch Service 2.2 → 5.5
Overview
When upgrading AWS Elasticsearch Service (ES) from 2.3 to 5.5, I put together
the following notes.
High-level flow
- Take a snapshot from the ES 2.3 domain
- Create an ES 5.5 domain
- Switch the application’s fluentd destination to the ES 5.5 domain
- Restore the data into the ES 5.5 domain
- Delete the ES 2.3 domain
Checking the current version
1 | $ curl https://<Elasticsearch 2.3 Endpoint Domain> |
Also, check the cluster settings in the AWS console
Take notes of the other settings configured on the cluster.
- Instance type
- Access policy
Managing AWS Elasticsearch Service snapshots in S3
Create an IAM role
- Create it as an ec2 type
- Without setting any permissions, click the “Next Step” button
- Name the role es-index-backups and create it
You can confirm that it was created with the role ARN arn:aws:iam::
- Edit the trust relationship
Edit Service to es.amazonaws.com
1 | { |
Create an IAM User
- Select Users > Add user
- Set the user name to
es-index-backup-user, check Programmatic access, and clickNext Step
- Without attaching any policy, click
Next Step
- Create
es-index-backup-userand attach a custom policy that grants access to the role created earlier.
1 | { |
- Make a note of the issued access key and secret access key.
Create an S3 bucket
Create a bucket via S3 > Create bucket.
Create a snapshot repository in Elasticsearch
You need to create a repository in Elasticsearch to manage the snapshots.
Run the following script on a server that can access Elasticsearch.
- register_es_repository.py
1 | from boto.connection import AWSAuthConnection |
1 | $ chmod +x register_es_repository.py |
Repository registration is complete.
Take a snapshot
Let’s name the snapshot 20170926.
1 | $ curl -XPUT "https://<Elasticsearch 2.3 Endpoint Domain>/_snapshot/index-backups/20170926" |
List snapshots
You can confirm that the snapshot was taken with the name 20170926.
1 | $ curl -s -XGET "https://<Elasticsearch 2.3 Endpoint Domain>/_snapshot/index-backups/_all" | jq . |
Delete a snapshot
To delete the snapshot 20170926, run the DELETE method.
1 | $ curl -XDELETE https://<Elasticsearch 2.3 Endpoint Domain>/_snapshot/index-backups/20170926 |
Check S3
You can see that the following have been created.
- indices/*
- meta-*
- snap-*
At first I assumed it was done once meta-_ was created, but
it turned out you also have to wait until snap-_ is created.
- It’s more reliable to confirm snapshot completion from the CLI.
1 | $ curl -s -GET https://<Elasticsearch 2.3 Endpoint Domain>/_snapshot/index-backups/20170926 |
Create a new Elasticsearch 5.5 Service domain
Create it following the same settings as Elasticsearch 2.3.
Create the repository
- register_es55_repository.py
Modify the host part of register_es_repository.py to point to the new domain.
1 | from boto.connection import AWSAuthConnection |
1 | $ chmod +x register_es55_repository.py |
Restore from the snapshot
Restore the 20170926 snapshot.
1 | $ curl -XPOST "https://<Elasticsearch 5.5 Endpoint Domain>/_snapshot/index-backups/20170926/_restore" |
Verify the restore
1 | $ curl -XGET "https://<Elasticsearch 5.5 Endpoint Domain>/_cat/indices" |
A case where the snapshot restore fails
- The .kibana index already exists and cannot be restored.
1 | { |
Workaround
1 | curl -XPOST https://<Elasticsearch 5.5 Endpoint Domain>/_snapshot/index-backups/20170926/_restore -d '{ |
Using indices, you can restore only the indices in the snapshot that match a given regular expression.
This is the approach I took to work around the issue.
If there’s a better way, I’d be grateful for your advice.
By the way
When I performed the ES 2.2 → 5.5 upgrade with Terraform,
the update finally completed after more than an hour had elapsed.
1 | aws_elasticsearch_domain.elasticsearch: Still destroying... (ID: arn:aws:es:ap-northeast-1:xxxxxxxxxxxx:domain/***, 59m11s elapsed) |
That’s painful (>_<)
When managing with Terraform,
it’s faster to take a snapshot and then delete the domain from the AWS console.
I concluded that the most reliable approach is the blue-green style: create ES 5.5,
switch over from ES 2.2, run it for a while, and delete ES 2.2 once there are no problems.

