Esempio n. 1
0
 def elasticsearch_fail():
     es = Elasticsearch([{
         'host': 'example.com',
         'port': 9999
     }],
                        timeout=0.1)
     es.info()
Esempio n. 2
0
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)

    es_interface = ElasticsearchInterface(es_instance)

    es_meta = ES_META[index_name]
    try:
        results = es_interface.search(es_meta.alias, es_meta.type, body=q)
        report_and_fail_on_shard_failures(results)
        return results
    except ElasticsearchException as e:
        raise ESError(e)
Esempio n. 3
0
def get_es_new():
    """
    Get a handle to the configured elastic search DB.
    Returns an elasticsearch.Elasticsearch instance.
    """
    hosts = _es_hosts()
    return Elasticsearch(hosts, timeout=30, serializer=ESJSONSerializer())
Esempio n. 4
0
 def _bad_es_getter():
     from corehq.util.es.elasticsearch import Elasticsearch
     return Elasticsearch(
         [{
             'host': settings.ELASTICSEARCH_HOST,
             'port': settings.ELASTICSEARCH_PORT - 2,  # bad port
         }],
         timeout=0.1,
     )
Esempio n. 5
0
def _client(**override_kw):
    """Configure an elasticsearch.Elasticsearch instance."""
    hosts = _elastic_hosts()
    client_kw = {
        "timeout": settings.ES_SEARCH_TIMEOUT,
        "serializer": ElasticJSONSerializer(),
    }
    client_kw.update(override_kw)
    return Elasticsearch(hosts, **client_kw)
Esempio n. 6
0
def get_es_new():
    """
    Get a handle to the configured elastic search DB.
    Returns an elasticsearch.Elasticsearch instance.
    """
    hosts = _es_hosts()
    es = Elasticsearch(hosts,
                       timeout=settings.ES_SEARCH_TIMEOUT,
                       serializer=ESJSONSerializer())
    return es
Esempio n. 7
0
def get_es_export():
    """
    Get a handle to the configured elastic search DB with settings geared towards exports.
    Returns an elasticsearch.Elasticsearch instance.
    """
    hosts = _es_hosts()
    return Elasticsearch(
        hosts,
        retry_on_timeout=True,
        max_retries=3,
        # Timeout in seconds for an elasticsearch query
        timeout=300,
        serializer=ESJSONSerializer(),
    )