Reputation: 2560
I am using aws elastic search and I am restoring some indices to my elastic search to do so I use two approches:
1) I use curl as follows:
curl -XPOST 'xxxxxxx.us-east-1.es.amazonaws.com/_snapshot/test/snapshot_4/_restore' -d '{"indices": "movies"}'
Which works fine. Now I am trying to automate the process so I use python to do so and here is my code:
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())
And when I run it I get :
{"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}
What is the problem? Should I add anyb parameter to the client request? Why the curl works then? Is tehre any parameter I need to add to the python API request?
Upvotes: 0
Views: 1103
Reputation: 167
try this :
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)
this should do the magic and connect you to AWS
I'm connecting to 127.0.0.1 because I created a tunnel to my elastic search in AWS so in case you are not using tunnel you can use it direct
Upvotes: 1