def es_get(): from pyelasticsearch import ElasticSearch from django.conf import settings connection = get_thread_var('es_connetion') if not connection: connection = ElasticSearch( 'http://%s:%s/' % (settings.ES['default']['HOST'], settings.ES['default']['PORT'])) set_thread_var('es_connetion', connection) return connection
def mongo_get(collection=None): from django.conf import settings from pymongo import Connection connection = get_thread_var('mongo_connection') if not connection: connection = Connection()[settings.MONGO['default']['NAME']] set_thread_var('mongo_connection', connection) if connection and collection: if hasattr(collection, '_meta'): return connection[collection._meta.db_table] return connection[collection] return connection
def es_utils_get(doctypes=None): # basic_s = S().es(urls=[URL]).indexes(INDEX).doctypes(DOCTYPE) from django.conf import settings connection = get_thread_var('es_utils_connetion') if not connection: from elasticutils import S # s = S().indexes('dbvestlitecms').doctypes('product') connection = S().es().indexes(settings.ES['default']['NAME']) # ElasticSearch('%s:%s/' % (settings.ES['default']['HOST'], settings.ES['default']['PORT'])) set_thread_var('es_utils_connetion', connection) if doctypes: return connection.doctypes(doctypes) return connection
def process_request(self, request): set_thread_var('request', request)