use mapping to fix error for temp backup index

This commit is contained in:
simon 2022-11-20 16:13:30 +07:00
parent e101c4abc7
commit 0c8fcbd724
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
1 changed files with 7 additions and 2 deletions

View File

@ -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: