英文:
Need Python to reindex Elasticsearch index
问题
# 我需要使用Python重新索引Elasticsearch中的索引。
# 但在"es.reindex(...)"部分出现错误
# "TypeError: 无法在Elasticsearch API方法中使用位置参数,只能使用关键字参数。"
# 如何修复这个问题?
from datetime import datetime
from elasticsearch import Elasticsearch
nodes = ['http://localhost:9200/']
es = Elasticsearch(nodes)
print(es.info().body)
indexPrefix = "test-index"
res = es.indices.get(
index=f"{indexPrefix}*"
)
indices = []
for index in res:
indices.append(index)
no_of_indices = len(indices)
print(indices, no_of_indices)
for source_index in indices:
destination_index = "test-neu-2"
result = es.reindex({
"source": {"index": source_index},
"dest": {"index": destination_index}
}, wait_for_completion=True)
print(result)
英文:
I need python to reindex indices in Elasticsarch.
But on the "es.reindex(...)" I get an error
"TypeError: Positional arguments can't be used with Elasticsearch API methods. Instead only use keyword arguments."
How to fix this?
from datetime import datetime
from elasticsearch import Elasticsearch
nodes = ['http://localhost:9200/']
es = Elasticsearch(nodes)
print(es.info().body)
indexPrefix = "test-index"
res = es.indices.get(
index=f"{indexPrefix}*"
)
indices = []
for index in res:
indices.append(index)
no_of_indices = len(indices)
print(indices, no_of_indices)
for source_index in indices:
destination_index = "test-neu-2"
result = es.reindex({
"source": {"index": source_index},
"dest": {"index": destination_index}
}, wait_for_completion=True)
print (result)
Tried to use internetsearch but could not find a solution how to fix the code
答案1
得分: 0
根据您的错误消息报告,不允许使用位置参数。 您缺少关键字参数 body
:
for source_index in indices:
destination_index = "test-neu-2"
result = es.reindex(
body={
"source": {"index": source_index},
"dest": {"index": destination_index}
},
wait_for_completion=True)
英文:
as reported by your error message, positional arguments
es.reindex({ "source": {"index": source_index}, "dest": {"index": destination_index}}, wait_for_completion=True)
are not allowed. You're missing the keyword argument body
:
for source_index in indices:
destination_index = "test-neu-2"
result = es.reindex(
body={
"source": {"index": source_index},
"dest": {"index": destination_index}
},
wait_for_completion=True)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论