Permalink
Browse files

[bug 856233] Fix index call

We updated to a new elasticutils which has differen bulk_index args.

Plus bulk_index doesn't chunk the indexing, so I dropped the chunk
size to 100 which is a better chunk size for bulk indexing.
  • Loading branch information...
1 parent affcf12 commit dc68d44cfb6a5f2fa363fcef005e40eedd535aa4 @willkg willkg committed Apr 1, 2013
Showing with 9 additions and 10 deletions.
  1. +9 −10 apps/questions/cron.py
View
@@ -10,7 +10,7 @@
from questions.models import Question, QuestionVote
from questions.tasks import update_question_vote_chunk
-from search.es_utils import ES_EXCEPTIONS, WRITE_INDEX, get_documents, get_es
+from search.es_utils import ES_EXCEPTIONS, get_documents
from search.tasks import index_task
from sumo.utils import chunked
@@ -88,8 +88,6 @@ def auto_lock_old_questions():
if settings.ES_LIVE_INDEXING:
try:
- es = get_es()
-
# So... the first time this runs, it'll handle 160K
# questions or so which stresses everything. Thus we
# do it in chunks because otherwise this won't work.
@@ -98,24 +96,25 @@ def auto_lock_old_questions():
# the chunking code.
from search.utils import chunked
- for chunk in chunked(q_ids, 1000):
+ for chunk in chunked(q_ids, 100):
# Fetch all the documents we need to update.
es_docs = get_documents(Question, chunk)
log.info('Updating %d index documents', len(es_docs))
+ documents = []
+
# For each document, update the data and stick it
# back in the index.
for doc in es_docs:
doc[u'question_is_locked'] = True
- Question.index(doc, bulk=True, es=es)
+ documents.append(doc)
- es.flush_bulk(forced=True)
- es.refresh(WRITE_INDEX, timesleep=0)
+ Question.bulk_index(documents, id_field='document_id')
except ES_EXCEPTIONS:
- # Something happened with ES, so let's push index updating
- # into an index_task which retries when it fails because
- # of ES issues.
+ # Something happened with ES, so let's push index
+ # updating into an index_task which retries when it
+ # fails because of ES issues.
index_task.delay(Question, q_ids)

0 comments on commit dc68d44

Please sign in to comment.