我正在使用 python 访问 elasticsearch 集群。现在我想使用快照备份我的索引。 最困难的是:python-elasticsearch 的文档只给我一个 API 描述。没有示例向我展示如何创建快照。我尝试了一些参数,但失败了。任何人都可以使用 python 给出 Elasticsearch 的快照示例吗?以下是我的代码:
from elasticsearch import Elasticsearch
es = Elasticsearch()
snapshot_body = {
"type": "url",
"settings": {
"url": "http://download.elasticsearch.org/definitiveguide/sigterms_demo/"
}
}
body = {"snapshot": snapshot_body}
es.snapshot.create_repository(repository='test', body=body)
最佳答案
您的存储库创建几乎是正确的,您不需要行 body = {"snapshot": snapshot_body}
,只需像这样创建您的存储库:
es.snapshot.create_repository(repository='test', body=snapshot_body)
现在为了创建快照,您所要做的就是:
es.snapshot.create(repository='test', snapshot='my_snapshot')
如果你只想存储一些索引而不是全部你也可以提供这样的主体:
index_body = {
"indices": "index_1,index_2"
}
es.snapshot.create(repository='test', snapshot='my_snapshot', body=index_body)
关于python - 任何人都可以使用 python 给出 Elasticsearch 的快照示例吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41215243/