def run_query(index_name, q, debug_host=None): # the debug_host parameter allows you to query another env for testing purposes if debug_host: if not settings.DEBUG: raise Exception("You can only specify an ES env in DEBUG mode") es_host = settings.ELASTICSEARCH_DEBUG_HOSTS[debug_host] es_instance = Elasticsearch([{ 'host': es_host, 'port': settings.ELASTICSEARCH_PORT }], timeout=3, max_retries=0) else: es_instance = get_es_new() try: es_meta = ES_META[index_name] except KeyError: from corehq.apps.userreports.util import is_ucr_table if is_ucr_table(index_name): es_meta = EsMeta(index_name, 'indicator') else: raise try: return es_instance.search(es_meta.index, es_meta.type, body=q) except ElasticsearchException as e: raise ESError(e)
def __init__(self, index=None, debug_host=None, es_instance_alias=ES_DEFAULT_INSTANCE): from corehq.apps.userreports.util import is_ucr_table self.index = index if index is not None else self.index if self.index not in ES_META and not is_ucr_table(self.index): msg = "%s is not a valid ES index. Available options are: %s" % ( index, ', '.join(ES_META)) raise IndexError(msg) self.debug_host = debug_host self._default_filters = deepcopy(self.default_filters) self._aggregations = [] self._source = None self.es_instance_alias = es_instance_alias self.es_query = { "query": { "filtered": { "filter": { "and": [] }, "query": queries.match_all() } } }
def run_query(index_name, q, debug_host=None): # the debug_host parameter allows you to query another env for testing purposes if debug_host: if not settings.DEBUG: raise Exception("You can only specify an ES env in DEBUG mode") es_host = settings.ELASTICSEARCH_DEBUG_HOSTS[debug_host] es_instance = Elasticsearch([{'host': es_host, 'port': settings.ELASTICSEARCH_PORT}], timeout=3, max_retries=0) else: es_instance = get_es_new() try: es_meta = ES_META[index_name] except KeyError: from corehq.apps.userreports.util import is_ucr_table # todo: figure out if we really need types if is_ucr_table(index_name): es_meta = EsMeta(index_name, 'indicator') else: raise try: return es_instance.search(es_meta.index, es_meta.type, body=q) except ElasticsearchException as e: raise ESError(e)
def run_query(index_name, q, debug_host=None, es_instance_alias=ES_DEFAULT_INSTANCE): # the debug_host parameter allows you to query another env for testing purposes if debug_host: if not settings.DEBUG: raise Exception("You can only specify an ES env in DEBUG mode") es_host = settings.ELASTICSEARCH_DEBUG_HOSTS[debug_host] es_instance = Elasticsearch([{'host': es_host, 'port': settings.ELASTICSEARCH_PORT}], timeout=3, max_retries=0) else: es_instance = get_es_instance(es_instance_alias) try: es_meta = ES_META[index_name] except KeyError: from corehq.apps.userreports.util import is_ucr_table if is_ucr_table(index_name): es_meta = EsMeta(index_name, 'indicator') else: raise try: results = es_instance.search(es_meta.index, es_meta.type, body=q) report_and_fail_on_shard_failures(results) return results except ElasticsearchException as e: raise ESError(e)
def __init__(self, index=None, debug_host=None, es_instance_alias=ES_DEFAULT_INSTANCE): from corehq.apps.userreports.util import is_ucr_table self.index = index if index is not None else self.index if self.index not in ES_META and not is_ucr_table(self.index): msg = "%s is not a valid ES index. Available options are: %s" % ( index, ', '.join(ES_META)) raise IndexError(msg) self.debug_host = debug_host self._default_filters = deepcopy(self.default_filters) self._aggregations = [] self.es_instance_alias = es_instance_alias self.es_query = {"query": { "filtered": { "filter": {"and": []}, "query": queries.match_all() } }}