Beispiel #1
0
    def index_batch(cls, batch):
        """
        Index the specified batch.
        """

        conn = get_es_connection()
        es_helpers.bulk(client=conn, actions=batch)
Beispiel #2
0
def get_elasticsearch_info(full):
    try:
        props = get_es_connection().info()
        if full:
            return props
        return {'version': props['version']}
    except ElasticsearchException:
        logger.exception("Could not connect to Elasticsearch.")
        return {
            'version': 'unknown',
            'error': 'Error connecting to Elasticsearch. Check the logs for more detail.'
        }
Beispiel #3
0
def get_test_client(nowait=False):
    client = get_es_connection('default')

    # wait for yellow status
    for _ in range(1 if nowait else 5):
        try:
            client.cluster.health(wait_for_status="yellow")
            return client
        except ConnectionError:
            time.sleep(0.1)
    else:
        # timeout
        raise SkipTest("Elasticsearch failed to start")
Beispiel #4
0
    def save_to_elasticsearch(components):
        logger.info("Saving to Elasticsearch...")
        conn = get_es_connection()
        count = 0

        for ok, result in es_helpers.streaming_bulk(conn, components):
            action, result = result.popitem()
            doc_id = result['_id']
            doc = '/%s/%s' % (result['_index'], doc_id)

            if not ok:
                logger.error('Failed to %s document %s: %r' %
                             (action, doc, result))
            else:
                logger.debug('Saved document %s: %r' % (doc, result))
                count += 1

            yield ok, count

        logger.info("Documents saved to Elasticsearch")
Beispiel #5
0
def get_elasticsearch_info():
    return get_es_connection().info()
Beispiel #6
0
 def cleanup_elasticsearch(task):
     logger.info("Deleting task tags already in Elasticsearch...")
     conn = get_es_connection()
     Search(using=conn, index='_all').query('term',
                                            task_id=str(task.pk)).delete()
     logger.info("Deleted task tags already in Elasticsearch")