def reindex(session, es, request): """Reindex all annotations into a new index, and update the alias.""" aliased = es.get_aliased_index() is not None # If the index we're using is an alias, then we index into a brand new # index and update the alias at the end. if aliased: new_index = es.index + '-' + _random_id() configure_index(es, index=new_index) indexer = BatchIndexer(session, es, request, target_index=new_index) else: indexer = BatchIndexer(session, es, request) errored = indexer.index() if errored: log.debug('failed to index {} annotations, retrying...'.format( len(errored))) errored = indexer.index(errored) if errored: log.warn('failed to index {} annotations: {!r}'.format( len(errored), errored)) if aliased: es.update_aliased_index(new_index) else: deleter = BatchDeleter(session, es) deleter.delete_all()
def includeme(config): settings = config.registry.settings settings.setdefault('es.host', 'http://localhost:9200') settings.setdefault('es.index', 'hypothesis') # Allow users of this module to register additional search filter and # search matcher factories. config.registry[FILTERS_KEY] = [] config.registry[MATCHERS_KEY] = [] config.add_directive('add_search_filter', lambda c, f: c.registry[FILTERS_KEY].append(f)) config.add_directive('add_search_matcher', lambda c, m: c.registry[MATCHERS_KEY].append(m)) # Add a property to all requests for easy access to the elasticsearch # client. This can be used for direct or bulk access without having to # reread the settings. config.add_request_method( lambda r: _get_client(r.registry.settings), name='es', reify=True) # If requested, automatically configure the index if asbool(settings.get('h.search.autoconfig', False)): configure_index(_get_client(settings))
def test_sets_correct_mappings_and_settings(self, client): configure_index(client) client.conn.indices.create.assert_called_once_with( mock.ANY, body={ 'mappings': {'annotation': ANNOTATION_MAPPING}, 'settings': {'analysis': ANALYSIS_SETTINGS}, })
def test_sets_correct_mappings_and_settings(self, client): configure_index(client) client.conn.indices.create.assert_called_once_with( mock.ANY, body={ 'mappings': { 'annotation': ANNOTATION_MAPPING }, 'settings': { 'analysis': ANALYSIS_SETTINGS }, })
def reindex(session, es, request): """Reindex all annotations into a new index, and update the alias.""" if get_aliased_index(es) is None: raise RuntimeError('cannot reindex if current index is not aliased') settings = request.find_service(name='settings') new_index = configure_index(es) try: settings.put(SETTING_NEW_INDEX, new_index) request.tm.commit() indexer = BatchIndexer(session, es, request, target_index=new_index, op_type='create') errored = indexer.index() if errored: log.debug('failed to index {} annotations, retrying...'.format( len(errored))) errored = indexer.index(errored) if errored: log.warn('failed to index {} annotations: {!r}'.format( len(errored), errored)) update_aliased_index(es, new_index) finally: settings.delete(SETTING_NEW_INDEX) request.tm.commit()
def test_returns_index_name(self, client, matchers): name = configure_index(client) assert name == matchers.regex('foo-[0-9a-f]{8}')
def test_creates_randomly_named_index(self, client, matchers): configure_index(client) client.conn.indices.create.assert_called_once_with( matchers.regex('foo-[0-9a-f]{8}'), body=mock.ANY)