Example #1
0
def drop_elastic(app):
    with app.app_context():
        try:
            es = get_es(app.config['ELASTICSEARCH_URL'])
            get_indices(es).delete(app.config['ELASTICSEARCH_INDEX'])
        except elasticsearch.exceptions.NotFoundError:
            pass
 def run(self, index_name=None):
     # if no index name is passed then use the configured one
     index_name = index_name if index_name else superdesk.app.config['ELASTICSEARCH_INDEX']
     print('Starting index rebuilding for index: {}'.format(index_name))
     if index_name not in self._get_available_indexes():
         raise Exception("Index {} is not configured".format(index_name))
     try:
         es = get_es(superdesk.app.config['ELASTICSEARCH_URL'])
         clone_name = index_name + '-' + get_random_string()
         print('Creating index: ', clone_name)
         superdesk.app.data.elastic.create_index(clone_name, superdesk.app.config['ELASTICSEARCH_SETTINGS'])
         real_name = superdesk.app.data.elastic.get_index_by_alias(clone_name)
         print('Putting mapping for index: ', clone_name)
         superdesk.app.data.elastic.put_mapping(superdesk.app, clone_name)
         print('Starting index rebuilding.')
         reindex(es, index_name, clone_name)
         print('Finished index rebuilding.')
         print('Deleting index: ', index_name)
         get_indices(es).delete(index_name)
         print('Creating alias: ', index_name)
         get_indices(es).put_alias(index=real_name, name=index_name)
         print('Alias created.')
         print('Deleting clone name alias')
         get_indices(es).delete_alias(name=clone_name, index=real_name)
         print('Deleted clone name alias')
     except elasticsearch.exceptions.NotFoundError as nfe:
         print(nfe)
     print('Index {0} rebuilt successfully.'.format(index_name))
Example #3
0
def drop_elastic(app):
    with app.app_context():
        es = get_es(app.config['ELASTICSEARCH_URL'])
        indexes = [app.config['ELASTICSEARCH_INDEX']] + list(app.config['ELASTICSEARCH_INDEXES'].values())
        for index in indexes:
            try:
                es.indices.delete(index)
            except elasticsearch.exceptions.NotFoundError:
                pass
 def run(self):
     index_name = superdesk.app.config['ELASTICSEARCH_INDEX']
     print('Starting index rebuilding for index: ', index_name)
     try:
         es = get_es(superdesk.app.config['ELASTICSEARCH_URL'])
         clone_name = index_name + '-' + get_random_string()
         print('Creating index: ', clone_name)
         superdesk.app.data.elastic.create_index(clone_name, superdesk.app.config['ELASTICSEARCH_SETTINGS'])
         print('Putting mapping for index: ', clone_name)
         superdesk.app.data.elastic.put_mapping(superdesk.app, clone_name)
         print('Starting index rebuilding.')
         reindex(es, index_name, clone_name)
         print('Finished index rebuilding.')
         print('Deleting index: ', index_name)
         get_indices(es).delete(index_name)
         print('Creating alias: ', index_name)
         get_indices(es).put_alias(index=clone_name, name=index_name)
         print('Alias created.')
     except elasticsearch.exceptions.NotFoundError as nfe:
         print(nfe)
     print('Index {0} rebuilt successfully.'.format(index_name))