Elsaticsearch reindex zero downtime
I think this is the most straightforward strategy and super easy way
let’s say…
petshop-index = currently index that we use
petshop-index_v2 = new index
STEP1 :
Add the new aliases to petshop-index as assume naming it to petshop-index_latest ( The reason why I naming it like that because if we want to reindex in the next time we don't need to re-point an application to use new aliases just keep it latest :) )
POST _aliases
{
"actions": [
{
"add": {
"alias": "petshop-index_latest",
"index": "petshop-index"
}
}
]
}
STEP2 :
Create a new index that you want to reindex (change the mapping, field type, etc)
PUT /petshop-index_v2
{
"settings": {
"index": {
"number_of_shards": 10,
"sort.field" : "bill_date",
"sort.order": "desc"
}
},
"mappings": {
...
}
}
STEP3 :
After you already have a new index it’s time to move all incoming traffic to the new index by changing aliases. Formally we point
[ petshop-index_latest ->petshop-index ]
but now we have to change it to
[ petshop-index_latest ->petshop-index_v2 ]
So, when you finished doing that you can count a document and you’ll see all traffic come to petshop-index_v2 instead of petshop-index
POST _aliases
{
"actions": [
{
"remove": {
"alias": "petshop-index_latest",
"index": "petshop-index"
}
},
{
"add": {
"alias": "petshop-index_latest",
"index": "petshop-index_v2"
}
}
]
}
STEP4 :
Reindex your own data move from petshop-index to petshop-index_v2
POST _reindex?wait_for_completion=false
{
"source": {
"index": "petshop-index"
},
"dest": {
"index": "petshop-index_v2"
}
}
Note: use wait_for_completion for running reindex task in the background process. It gonna return task id so, you can check it out how about your process by using TaskAPI
GET /_tasks/O0bQQ8VYQ0yiWNrDaTmrtA:20830445
Happy searching….
Ref:
Good cover image by:
Photo by Austin Neill on Unsplash