How to fix Spotlight when it keeps indexing in Mac OS X Lion

Today I noticed that the fan of my MacBook was continuously spinning because my Spotlight kept indexing for hours. Even when it was finished, a couple moments later it started reindexing again. After searching Google for a while finding no working solutions, I finally found one that worked for me.

Spotlight keeps indexing – the fix

If you execute the following command in your Terminal (Applications/Utilities) Spotlight should stop indexing (N.B. make sure you copy it exactly.):

sudo rm -rf /.Spotlight-V100/*

Re-index Spotlight

The above command deletes your current corrupted index. Now execute the following command to force a re-index of Spotlight for one-time(If it gives you a -400 error, rebooting and trying again should work). After running the command, Spotlight should start re-indexing within a minute.

sudo mdutil -i on -E /

Please note: It might seem that the problem hasn’t been solved, but the second command tells Spotlight to do a real, proper reindex. If everything is okay, it doesn’t reindex indefinitely now, but should be done in a couple of hours.

This is not a permanent solution, as the problem happened to me twice in the last eight months. So if your Spotlight keeps indexing too, please do let me know it it worked for you, and if you have any other solutions or know the root cause of this problem.