def clone_index(use_helper, from_index, to_index):
"""Clone an index"""
from elasticsearch_dsl import Search
from elasticsearch.helpers import reindex
click.clear()
if not es.client.indices.exists(index=to_index):
click.secho('%s not existing!'.format(to_index), fg='red')
return 1
cnt = Search(using=es.client, index=to_index).count()
message = 'Index %s already exists (%d records). Overwrite?' % (
to_index, cnt)
click.confirm(message, abort=True)
if use_helper:
reindex(
client=es.client,
source_index=from_index,
target_index=to_index)
else:
es.client.reindex(
body=dict(
source=dict(index=from_index),
dest=dict(index=to_index)),
wait_for_completion=False)
评论列表
文章目录