我正在使用aws弹性搜索,我正在恢复一些索引到我的弹性搜索,所以我使用两个approches:
1)我使用curl如下:
curl -XPOST 'xxxxxxx.us-east-1.es.amazonaws.com/_snapshot/test/snapshot_4/_restore' -d '{"indices": "movies"}'
哪个工作正常。 现在我正在尝试自动化这个过程,所以我使用python这样做,这是我的代码:
from boto.connection import AWSAuthConnection
class ESConnection(AWSAuthConnection):
def __init__(self, region, **kwargs):
super(ESConnection, self).__init__(**kwargs)
self._set_auth_region_name(region)
self._set_auth_service_name("es")
def _required_auth_capability(self):
return ['hmac-v4']
if __name__ == "__main__":
clientDestination = ESConnection(
region='us-east-1',
host=xxxxxxx.es.amazonaws.com',
aws_access_key_id='xxxxxxx',
aws_secret_access_key='xxxxx', is_secure=False)
print("Restoring snapshots")
resprestore = clientSource.make_request(method='POST',
path='/_snapshot/test/snapshot_4/_restore',
data='{"indices": "movies"}')
print(resprestore.read())
当我跑步时,我得到:
{"error":{"root_cause":[{"type":"snapshot_restore_exception","reason":"[test:snapshot_4/DR01R_WRR2ihiiKe1HgrzA] cannot restore index [movies] because it's open"}],"type":"snapshot_restore_exception","reason":"[test:snapshot_4/DR01R_WRR2ihiiKe1HgrzA] cannot restore index [movies] because it's open"},"status":500}
有什么问题?我应该在客户端请求中添加anyb参数吗?为什么卷曲会起作用呢?是否需要添加到python API请求的任何参数?
答案 0 :(得分:1)
尝试:
from elasticsearch import Elasticsearch, RequestsHttpConnection
es = Elasticsearch(host=“127.0.0.1”, port=1234, use_ssl=True, verify_certs=False,connection_class=RequestsHttpConnection)
print(es)
这应该神奇,并将您连接到AWS
我正在连接到127.0.0.1,因为我在AWS中创建了通往弹性搜索的隧道 因此,如果您不使用隧道,则可以直接使用