From 0c8fcbd724dd6f371c80ac8deff1275834a8cec8 Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 20 Nov 2022 16:13:30 +0700 Subject: [PATCH] use mapping to fix error for temp backup index --- tubearchivist/home/src/es/index_setup.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tubearchivist/home/src/es/index_setup.py b/tubearchivist/home/src/es/index_setup.py index 109b88c..d7e2d03 100644 --- a/tubearchivist/home/src/es/index_setup.py +++ b/tubearchivist/home/src/es/index_setup.py @@ -100,6 +100,7 @@ class ElasticIndex: def rebuild_index(self): """rebuild with new mapping""" + self.create_blank(for_backup=True) self.reindex("backup") self.delete_index(backup=False) self.create_blank() @@ -126,15 +127,19 @@ class ElasticIndex: _, _ = ElasticWrap(path).delete() - def create_blank(self): + def create_blank(self, for_backup=False): """apply new mapping and settings for blank new index""" + path = f"ta_{self.index_name}" + if for_backup: + path = f"{path}_backup" + data = {} if self.expected_set: data.update({"settings": self.expected_set}) if self.expected_map: data.update({"mappings": {"properties": self.expected_map}}) - _, _ = ElasticWrap(f"ta_{self.index_name}").put(data) + _, _ = ElasticWrap(path).put(data) class BackupCallback: