You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python调用Elasticsearch reindex重命名索引时遇400错误

解决Elasticsearch Python客户端reindex时的400错误

错误的核心原因是reindex方法的source和dest参数必须传入字典类型,不能直接传字符串索引名。Elasticsearch的reindex API要求明确通过index键指定目标索引。

修正后的代码如下:

from elasticsearch import Elasticsearch

es_host = "https://localhost:9200"
password = "PASSWORD_STRING"

es_client = Elasticsearch(es_host, basic_auth=('elastic', password), verify_certs=False)

# 用字典格式传入source和dest参数,指定对应的索引名
reindex_result = es_client.reindex(
    source={"index": "transcripts"},
    dest={"index": "transcript_sent"}
)

print("重索引完成状态:", reindex_result)

# 若要实现真正的"重命名"(删除原索引),确认数据复制无误后执行:
# es_client.indices.delete(index="transcripts")

补充说明:

  • source字典中的index字段指定需要复制数据的原索引
  • dest字典中的index字段指定接收数据的目标索引
  • 原索引transcripts不会自动删除,若不需要保留,需手动调用删除接口

内容的提问来源于stack exchange,提问作者Varun Pandit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 07:12:08