Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions seeker/management/commands/reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
from seeker.registry import app_documents, documents
from seeker.utils import progress



def reindex(es, doc_class, index, options):
"""
Index all the things, using ElasticSearch's bulk API for speed.
"""

def get_actions():
for doc in doc_class.documents(cursor=options['cursor']):
action = {
Expand All @@ -22,11 +21,14 @@ def get_actions():
}
action.update(doc)
yield action

actions = get_actions() if options['quiet'] else progress(get_actions(), count=doc_class.count(), label=doc_class.__name__)
bulk(es, actions)
bulk_kwargs = {}
if options['timeout']:
bulk_kwargs['request_timeout'] = options['timeout']
bulk(es, actions, **bulk_kwargs)
es.indices.refresh(index=index)


class Command(BaseCommand):
args = '<app1 app2 ...>'
help = 'Re-indexes the specified applications'
Expand Down Expand Up @@ -72,6 +74,13 @@ def add_arguments(self, parser):
default=False,
help='Use a server-side cursor when fetching data for indexing',
)
parser.add_argument('--timeout',
action='store',
dest='timeout',
default=None,
type=int,
help='Sets the ES request timeout length in ms for indexing',
)
parser.add_argument('args', nargs=argparse.REMAINDER)

def handle(self, *args, **options):
Expand All @@ -83,7 +92,7 @@ def handle(self, *args, **options):
deleted_indexes = []
for doc_class in doc_classes:
using = options['using'] or doc_class._index._using or 'default'
index = doc_class._index._name # options['index'] or doc_class._doc_type.index or getattr(settings, 'SEEKER_INDEX', 'seeker')
index = doc_class._index._name # options['index'] or doc_class._doc_type.index or getattr(settings, 'SEEKER_INDEX', 'seeker')
es = connections.get_connection(using)
if options['drop'] and index not in deleted_indexes:
if es.indices.exists(index=index):
Expand Down