diff --git a/elasticsearch/transport.py b/elasticsearch/transport.py index 0326aaa4..b7801bc5 100644 --- a/elasticsearch/transport.py +++ b/elasticsearch/transport.py @@ -294,7 +294,7 @@ class Transport(object): if body is not None: try: - body = body.encode('utf-8', 'surrogatepass') + body = body.encode('utf-8', 'surrogatepass') except (UnicodeDecodeError, AttributeError): # bytes/str - no need to re-encode pass @@ -311,6 +311,10 @@ class Transport(object): connection = self.get_connection() try: + # add a delay before attempting the next retry + # 0, 1, 3, 7, etc... + delay = 2**attempt - 1 + time.sleep(delay) status, headers_response, data = connection.perform_request(method, url, params, body, headers=headers, ignore=ignore, timeout=timeout) except TransportError as e: