python - curl 请求以恢复 Elasticsearch 中的快照有效,但python中的相同请求不起作用

标签 python python-2.7 curl elasticsearch

我正在使用aws Elasticsearch ,并且正在将一些索引恢复到我的 Elasticsearch 中,因此我使用两个方法:

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参数吗?那么为什么 curl 呢?我需要向python API请求添加任何参数吗?

最佳答案

试试这个 :

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中创建了通往 Elasticsearch 的隧道
因此,如果您不使用隧道,则可以直接使用它

关于python - curl 请求以恢复 Elasticsearch 中的快照有效,但python中的相同请求不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47244623/

相关文章:

php - cUrl 无法从指定路径加载 pem 证书

python - 未知服务错误 botocore

python - 使用 python tkinter 布置框架时出现问题(框架内的框架使父框架不可见)

python - 在字典中查找所有可能性(Python 2.7)

matlab - 如何通过Python获取3D彩色表面?

php - 如何使用 cURL 将 PDF 内容作为应用程序/pdf 发布

linux - 在 Internet 存档上重定向后获取 URL

python - 在正则表达式中使用 unicode char 代码

Python 服务发现 : Advertise a service across a local network

python-2.7 - Dataframe 上的对数