I am trying to find a proper way how to reindex my elasticsearch index without downtime. I use python library for interacting with ES. The version of ES is 6.4.
Here is my workflow:
- Create two aliases one for searching and one for indexing.
- Point search alias to
old_indexandnew_index - Point index alias to
new_index - Call reindex API
- Wait for the reindexation process and remove search alias for
old_index - Remove
old_index
However this has one caveat in the form of duplicate records while I am reindexing. The record can be in both old_index and new_index.
Is there any way how to automatically delete records when they are moved new_ index?
I was trying something like this. Clearly this will delete all records in new_index instead of old_index
POST _reindex
{
"source": {
"index": "old_index"
},
"dest": {
"index": "new_index",
},
"script": {
"source": "ctx.op = 'delete'",
"lang": "painless"
}
}