Alexandru R
Alexandru R

Reputation: 8833

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?

Upvotes: 1

Views: 1851

Answers (2)

zbusia
zbusia

Reputation: 601

  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.

Upvotes: 2

Assael Azran
Assael Azran

Reputation: 2993

Try to change this helpers.reindex(client=es, source_index=index_old, target_index=index_new, ) to this helpers.reindex(client=es, source_index=index_old, target_index=index_new, bulk_kwargs={'wait_for_completion': True} )

Not tested.

Upvotes: 1

Related Questions