def reindex(self, model_name: str, table_name: str = None, index_suffix: str = None, **_): """ Copy contents of the database to a new Elasticsearch index. :param model_name: the name of the media type :param table_name: the name of the DB table, if different from model name :param index_suffix: the unique suffix to add to the index name """ if not index_suffix: index_suffix = uuid.uuid4().hex if not table_name: table_name = model_name destination_index = f"{model_name}-{index_suffix}" log.info(f"Creating index {destination_index} for model {model_name} " f"from table {table_name}.") self.es.indices.create( index=destination_index, body=index_settings(model_name), ) log.info("Running distributed index using indexer workers.") self.active_workers.value = int(True) schedule_distributed_index(database_connect(), model_name, table_name, destination_index, self.task_id)
def reindex(self, model_name: str, distributed=True): """ Copy contents of the database to a new Elasticsearch index. Create an index alias to make the new index the "live" index when finished. """ suffix = uuid.uuid4().hex destination_index = model_name + '-' + suffix if distributed: self.es.indices.create(index=destination_index, body=create_mapping(model_name)) schedule_distributed_index(database_connect(), destination_index) else: self._index_table(model_name, dest_idx=destination_index) self.go_live(destination_index, model_name)