Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating a Haystack search index with Django + Celery

In my Django project I am using Celery. I switched over a command from crontab to be a periodic task and it works well but it is just calling a method on a model. Is it possible to update my Haystack index from a periodic task as well? Has anyone done this?

/manage.py update_index 

That's the command to update the index from the Haystack documentation but I'm not sure how to call that from a task.

like image 626
knuckfubuck Avatar asked Dec 05 '10 12:12

knuckfubuck


2 Answers

the easiest way to do this would probably be to run the management command directly from python and run it in your task

from haystack.management.commands import update_index update_index.Command().handle() 
like image 183
Jann Avatar answered Sep 28 '22 14:09

Jann


As for version 2.0.0 beta of haystack, this code should work:

from haystack.management.commands import update_index update_index.Command().handle(using='default') 
like image 32
Wang Bin Avatar answered Sep 28 '22 14:09

Wang Bin