6

I deleted a record from django app, then I followed it up with up with update_index and the record was still searchable. I then used rebuild_index and that seemed to work when I ran the search again. But I do not know if my computer stuttered or what but when I when to my django app all my records were gone. but I panicked hit the refresh button on the browser a couple of times and they reappeared. What I'd like to be clear on is this is, after I delete a record from my django app I run

./manage.py rebuild_index 

and when I add a record to my django app I do this

./manage.py update_index. 

Is this correct syntax? I do not want to inadvertently delete all my records from a lack of understanding the aforementioned commands thanks. The docs are not fully clear to me.

giveJob
  • 1,500
  • 3
  • 17
  • 29
losee
  • 2,190
  • 3
  • 29
  • 55

1 Answers1

10

Avoid using rebuild_index to remove deleted objects from search index.

When you run the rebuild_index command, all index is deleted/ cleared using clear_index and then updated using update_index under the hood.

Use update_index command to update your search index. To removed deleted objects, you can pass --remove argument to the command so that it effectively delete obsolete objects.

$ python manage.py update_index --remove

This command will remove deleted objects from index.

Read more @ haystack docs / management commands

v1k45
  • 8,070
  • 2
  • 30
  • 38
  • 1
    is `update_index` only indexing missing results? or it updates everything again? because after running `rebuild_index` for the first time, I ran `update_index` and it showed `Indexing # results` with the total number of records. – eLRuLL Jun 08 '17 at 18:17
  • 2
    it is for re-indexing old updated objects and indexing new ones. It checks if the objects it has in index are up to date or not and also adds he ones which it does not have. – v1k45 Jun 08 '17 at 18:34