Reindexing elasticsearch and delete old records

Viewed 1265

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:

  1. Create two aliases one for searching and one for indexing.
  2. Point search alias to old_index and new_index
  3. Point index alias to new_index
  4. Call reindex API
  5. Wait for the reindexation process and remove search alias for old_index
  6. 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"
  }
}
0 Answers
Related