def index_batch(cls, batch): """ Index the specified batch. """ conn = get_es_connection() es_helpers.bulk(client=conn, actions=batch)
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.' }
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")
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")
def get_elasticsearch_info(): return get_es_connection().info()
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")