Created
February 13, 2015 22:31
-
-
Save bcavagnolo/c8b4b71dd0e08cd49522 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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