25 lines
858 B
Python
25 lines
858 B
Python
|
|
from django.core.management.base import BaseCommand
|
||
|
|
from django_elasticsearch_dsl.registries import registry
|
||
|
|
|
||
|
|
class Command(BaseCommand):
|
||
|
|
help = 'Reindexar todos os Diários Oficiais no Elasticsearch'
|
||
|
|
|
||
|
|
def handle(self, *args, **options):
|
||
|
|
self.stdout.write('Iniciando reindexação...')
|
||
|
|
|
||
|
|
# Recria os índices
|
||
|
|
registry.delete_indices()
|
||
|
|
registry.create_indices()
|
||
|
|
|
||
|
|
# Reindexar documentos
|
||
|
|
for index in registry.get_indices():
|
||
|
|
self.stdout.write(f'Reindexando {index}...')
|
||
|
|
documents = []
|
||
|
|
for doc in registry.get_documents():
|
||
|
|
if index == doc._index._name:
|
||
|
|
self.stdout.write(f' + {doc.__name__}')
|
||
|
|
doc().update()
|
||
|
|
|
||
|
|
self.stdout.write(self.style.SUCCESS('Reindexação concluída!'))
|
||
|
|
|