Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在弹性搜索中恢复快照的Curl请求起作用,但在python中相同的请求不起作用_Python_Python 2.7_Curl_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Python,Python 2.7,Curl,elasticsearch" /> elasticsearch,Python,Python 2.7,Curl,elasticsearch" />

在弹性搜索中恢复快照的Curl请求起作用,但在python中相同的请求不起作用

在弹性搜索中恢复快照的Curl请求起作用,但在python中相同的请求不起作用,python,python-2.7,curl,elasticsearch,Python,Python 2.7,Curl,elasticsearch,我正在使用aws弹性搜索,我正在将一些索引恢复到弹性搜索。为此,我使用了两种方法: 1) 我使用curl如下: curl -XPOST 'xxxxxxx.us-east-1.es.amazonaws.com/_snapshot/test/snapshot_4/_restore' -d '{"indices": "movies"}' 这很好用。 现在,我正在尝试将该过程自动化,因此我使用python来实现这一点,下面是我的代码: from boto.connection import AWSA

我正在使用aws弹性搜索,我正在将一些索引恢复到弹性搜索。为此,我使用了两种方法:

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参数吗?那么为什么卷曲有效呢?tehre是否有任何需要添加到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中创建了一个用于弹性搜索的隧道
因此,如果您不使用tunnel,您可以直接使用它

您可以显示从curl查询中获得的输出吗?@Val确定以下是我得到的结果:%Total%已接收%Xferd平均速度时间当前数据加载上载总花费的左速度100 38 100 17 100 21 8 100:00:02 0:00:01 0:00:01 10{“已接受”:true}@Val同样值得注意的是,我能够通过检查Kibana以查看恢复的结果来验证它是否正常工作