How*_*yan 4 python snapshot elasticsearch
我正在使用 python 访问 elasticsearch 集群。现在我想使用快照备份我的索引。最困难的是:python-elasticsearch 的文档只是给了我一个 API 描述。没有示例向我展示如何创建快照。我尝试了一些参数,但失败了。任何人都可以使用 python 给出弹性搜索的快照示例吗?以下是我的代码:
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)
Run Code Online (Sandbox Code Playgroud)
您的存储库创建几乎是正确的,您不需要该行body = {"snapshot": snapshot_body},只需像这样创建您的存储库:
es.snapshot.create_repository(repository='test', body=snapshot_body)
Run Code Online (Sandbox Code Playgroud)
现在为了创建快照,您所要做的就是:
es.snapshot.create(repository='test', snapshot='my_snapshot')
Run Code Online (Sandbox Code Playgroud)
如果您只想存储一些索引而不是全部,您还可以提供这样的主体:
index_body = {
"indices": "index_1,index_2"
}
es.snapshot.create(repository='test', snapshot='my_snapshot', body=index_body)
Run Code Online (Sandbox Code Playgroud)