kopia lustrzana https://github.com/wagtail/wagtail
refactor(search/elastic): cleanup AtomicRebuilder.finish() method
rodzic
27f50a527c
commit
b70823f2aa
|
@ -574,19 +574,11 @@ class ElasticSearchAtomicIndexRebuilder(ElasticSearchIndexRebuilder):
|
||||||
def finish(self):
|
def finish(self):
|
||||||
self.index.refresh()
|
self.index.refresh()
|
||||||
|
|
||||||
# Create the alias if it doesnt exist yet
|
if self.alias.is_alias():
|
||||||
if not self.alias.is_alias():
|
# Update existing alias, then delete the old index
|
||||||
# Make sure there isn't currently an index that clashes with alias
|
|
||||||
# This can happen when the atomic rebuilder is first enabled
|
|
||||||
self.alias.delete()
|
|
||||||
|
|
||||||
# Create the alias
|
# Find index that alias currently points to, we'll delete it after
|
||||||
self.index.put_alias(self.alias.name)
|
# updating the alias
|
||||||
|
|
||||||
else:
|
|
||||||
# Alias already exists, update it and delete old index
|
|
||||||
|
|
||||||
# Find index that alias currently points to, so we can delete it later
|
|
||||||
old_index = self.alias.aliased_indices()
|
old_index = self.alias.aliased_indices()
|
||||||
|
|
||||||
# Update alias to point to new index
|
# Update alias to point to new index
|
||||||
|
@ -598,6 +590,18 @@ class ElasticSearchAtomicIndexRebuilder(ElasticSearchIndexRebuilder):
|
||||||
if index.name != self.index.name:
|
if index.name != self.index.name:
|
||||||
index.delete()
|
index.delete()
|
||||||
|
|
||||||
|
else:
|
||||||
|
# self.alias doesn't currently refer to an alias in Elasticsearch.
|
||||||
|
# This means that either nothing exists in ES with that name or
|
||||||
|
# there is currently an index with the that name
|
||||||
|
|
||||||
|
# Run delete on the alias, just in case it is currently an index.
|
||||||
|
# This happens on the first rebuild after switching ATOMIC_REBUILD on
|
||||||
|
self.alias.delete()
|
||||||
|
|
||||||
|
# Create the alias
|
||||||
|
self.index.put_alias(self.alias.name)
|
||||||
|
|
||||||
|
|
||||||
class ElasticSearch(BaseSearch):
|
class ElasticSearch(BaseSearch):
|
||||||
index_class = ElasticSearchIndex
|
index_class = ElasticSearchIndex
|
||||||
|
|
Ładowanie…
Reference in New Issue