Skip to content

Instantly share code, notes, and snippets.

@bcavagnolo
Created February 13, 2015 22:31
Show Gist options
  • Save bcavagnolo/c8b4b71dd0e08cd49522 to your computer and use it in GitHub Desktop.
Save bcavagnolo/c8b4b71dd0e08cd49522 to your computer and use it in GitHub Desktop.
from elasticsearch import Elasticsearch, Urllib3HttpConnection
from pprint import pprint
class CompressedHttpConnection(Urllib3HttpConnection):
def __init__(self, *args, **kwargs):
super(CompressedHttpConnection, self).__init__(*args, **kwargs)
self.headers = {'Accept-Encoding': 'gzip,deflate'}
def perform_request(self, *args, **kwargs):
parent = super(CompressedHttpConnection, self)
status, headers, data = parent.perform_request(*args, **kwargs)
# urllib3 will automatically decompress your data. Expect the
# Content-Length header here to be smaller than without the
# compress header.
print str(headers)
return status, headers, data
es = Elasticsearch(connection_class=CompressedHttpConnection)
pprint(es.search())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment