18

My application usually takes 20 minutes to reindex as a whole. There is a small table with a couple of records which I want to reindex again. I want to save time so I ran the command rake sunspot:solr:reindex[500,Deal]. This is taken straight from the Github readme and is suppose to reindex one model only.

The time it takes to reindex in this command is still 20 minutes, so there is no difference in the time taken. Am I doing something wrong?

lulalala
  • 17,572
  • 15
  • 110
  • 169

2 Answers2

31

I was in the same situation of you asking why it takes the same time.

The solution: erase the ":solr". Just write:

rake sunspot:reindex[batch_size,Model]

If you don't specify the batch_size you have tu put a comma "," like:

rake sunspot:reindex[,model]
Matteo Alessani
  • 10,264
  • 4
  • 40
  • 57
francordie
  • 608
  • 5
  • 11
26

I now go into Rails console and call reindex from there:

Deal.solr_reindex(:batch_size => 1000, :include => :period)

This works great as I can now reindex only one model, include related tables to improve speed. Previously it is only indexing at 200/sec, and now it is at 1000/sec.

(In fact, since reindexing through console or rake will clear the index file, resulting in a short period of empty index, I now call solr_index most of the time to update the index.)

lulalala
  • 17,572
  • 15
  • 110
  • 169
  • 2
    The rake task for reindexing is somewhat naive. The bottleneck here is N+1 queries to your database for associated objects, and your use of `:include` in the console is saving a lot of overhead that is otherwise incurred in the rake task. – Nick Zadrozny Jan 26 '12 at 21:33
  • 2
    small addition to this solution: the included models need to be written in lowercase and depending on their kind of relation in singular or plural – ernd enson Dec 14 '12 at 20:34