def clean_es(app): with app.test_request_context('/'): es.initialize() es.cluster.health(index=es.index_name, wait_for_status='yellow', request_timeout=1) yield with app.test_request_context('/'): es.indices.delete(index=es.index_name, ignore=[400, 404])
def reindex(): '''Reindex all advices''' print('Deleting index {0}'.format(es.index_name)) if es.indices.exists(es.index_name): es.indices.delete(index=es.index_name) es.initialize() for idx, advice in enumerate(Advice.objects, 1): topics = [] for topic in advice.topics: topics.append(topic) parts = topic.split('/') if len(parts) > 1: topics.append(parts[0]) es.index(index=es.index_name, doc_type=DOCTYPE, id=advice.id, body={ 'id': advice.id, 'administration': advice.administration, 'type': advice.type, 'session': advice.session.strftime('%Y-%m-%d'), 'subject': advice.subject, 'topics': topics, 'tags': advice.tags, 'meanings': advice.meanings, 'part': advice.part, 'content': advice.content, }) print('.' if idx % 50 else idx, end='') es.indices.refresh(index=es.index_name) print('\nIndexed {0} advices'.format(idx))
def reindex(): '''Reindex all advices''' print('Deleting index {0}'.format(es.index_name)) if es.indices.exists(es.index_name): es.indices.delete(index=es.index_name) es.initialize() for idx, advice in enumerate(Advice.objects, 1): index(advice) print('.' if idx % 50 else idx, end='') es.indices.refresh(index=es.index_name) print('\nIndexed {0} advices'.format(idx))
def reindex(): '''Reindex all advices''' print('Deleting index {0}'.format(es.index_name)) if es.indices.exists(es.index_name): es.indices.delete(index=es.index_name) es.initialize() idx = 0 for idx, advice in enumerate(Advice.objects, 1): index(advice) print('.' if idx % 50 else idx, end='') es.indices.refresh(index=es.index_name) print('\nIndexed {0} advices'.format(idx))
def reindex(): '''Reindex all advices''' header('Reindexing all advices') echo('Deleting index {0}', white(es.index_name)) if es.indices.exists(es.index_name): es.indices.delete(index=es.index_name) es.initialize() idx = 0 for idx, advice in enumerate(Advice.objects, 1): index(advice) echo('.' if idx % 50 else white(idx), nl=False) echo(white(idx) if idx % 50 else '') es.indices.refresh(index=es.index_name) success('Indexed {0} advices', idx)