首页 > 解决方案 > 如何在 Python 中等待 elasticsearch helpers.reindex 完成?

问题描述

我正在重新索引一个大索引,需要删除旧索引才能为新索引添加别名。

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)

问题是最后2个命令需要等待reindex完成,否则会删除原来的索引,不起作用。

我看到 elasticsearch 有 refresh=wait_for 但不是 python helpers.reindex。

什么方法可以使重新索引同步?

标签: pythonelasticsearchelasticsearch-helpers

解决方案


  1. 作为文档统计信息,不推荐使用 helpers.reindex,首选主 API 重新索引。

  2. reindex 方法包含wait_for_completion默认为 true 的参数,因此默认情况下Elasticsearch().reindex(...)是同步的。


推荐阅读