in src/olympia/search/management/commands/reindex.py [0:0]
def handle(self, *args, **kwargs):
"""Reindexing work.
Creates a task chain that creates new indexes over the old ones so the
search feature works while the indexation occurs.
"""
force = kwargs['force']
if Reindexing.objects.is_reindexing() and not force:
raise CommandError('Indexation already occurring - use --force to bypass')
alias = settings.ES_INDEXES.get(kwargs['key'], None)
if alias is None:
raise CommandError(
'Invalid --key parameter. It should be one of: %s.'
% (self.accepted_keys())
)
self.stdout.write('Starting the reindexation for %s.' % alias)
if kwargs['skip_if_exists'] and ES.indices.exists_alias(name=alias):
self.stdout.write('Alias %s already exists. Skipping reindex.' % alias)
return
if kwargs['wipe']:
skip_confirmation = kwargs['noinput']
confirm = ''
if not skip_confirmation:
confirm = input(
'Are you sure you want to wipe all AMO '
'Elasticsearch indexes? (yes/no): '
)
while confirm not in ('yes', 'no'):
confirm = input('Please enter either "yes" or "no": ')
if confirm == 'yes' or skip_confirmation:
unflag_database()
# Retrieve the actual index and delete it. That way whether or
# not this was an alias or an index (which is wrong, but
# happens if data was indexed before the first reindex was
# done) doesn't matter.
try:
index = next(iter(ES.indices.get(index=alias)))
ES.indices.delete(index=index)
except NotFoundError:
pass
else:
raise CommandError('Aborted.')
elif force:
unflag_database()
workflow = self.create_workflow(alias)
self.execute_workflow(workflow)