File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
oscar_elasticsearch/search/indexing Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,20 @@ def finish(self):
83
83
# No indices yet, make alias from original name to alias name
84
84
es .indices .put_alias (name = self .name , index = self .alias_name )
85
85
86
+ # Get all indices associated with the alias
87
+ aliased_indices = list (
88
+ es .indices .get_alias (name = self .name , ignore_unavailable = True ).keys ()
89
+ )
90
+
91
+ # Find all indices matching the pattern but without an alias
92
+ all_indices = list (
93
+ es .indices .get (index = f"{ self .name } _*" , ignore_unavailable = True ).keys ()
94
+ )
95
+ unaliased_indices = set (all_indices ) - set (aliased_indices )
96
+
97
+ for index in unaliased_indices :
98
+ self .delete (index )
99
+
86
100
def create (self , name ):
87
101
return es .indices .create (
88
102
index = name , body = {"settings" : self .settings , "mappings" : self .mappings }
You can’t perform that action at this time.
0 commit comments