Search code examples
pythonelasticsearchelasticsearch-helpers

How to wait for elasticsearch helpers.reindex to finish in Python?


I'm reindexing a big index and need to delete the old index in order to add an alias to the new index.

helpers.reindex(client=es, source_index=index_old, target_index=index_new, )

# those 2 need to run when reindex finishes
es.indices.delete(index=index_old)
es.indices.put_alias(index=index_new, name=index_old)

The problem is that last 2 commands need to wait for reindex to finish, otherwise it will delete the original index and will not work.

I see elasticsearch has refresh=wait_for but not for python helpers.reindex.

What approach would be ok to make the reindex syncronous?


Solution

    1. As documentation stats, helpers.reindex is deprecated, and main API reindex is preferred.

    2. reindex method contains wait_for_completion param which is true by default, so by default Elasticsearch().reindex(...) is synchronous.