Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It seems that the search index for my has been corrupted. I have 4 years of emails, but when searching via the built-in search in it always returns no results. Anyone have any idea how the search index can be rebuilt or recreated in on OS X?

share|improve this question
up vote 5 down vote accepted

Prior to Lion Mail keeps its database at ~/Library/Mail/Envelope Index. For Lion it's ~/Library/Mail/V2/MailData/Envelope Index.

It's a sqlite database. To regenerate the entire file simply quit mail then delete the file. Mail will create a new one at next launch (it may take a while depending on the size of your mailboxes).

Caveate: I've only done this prior to Lion. I see in my MailData directory there are several files on Lion I'm not familiar with, so it may behave differently. You're responsible for backing up your own data before nuking anything.

share|improve this answer
Right, but this is the actual Mail database, correct? As in, all the emails and so and so forth. I wouldn't want to delete that, just the search index. I guess I could open the sqlite database and trawl through it hoping to find a search table that I could clear, but that would be uber-risky in the extreme... – Mahmoud Al-Qudsi Aug 22 '11 at 14:13
No it's not all the email messages themselves. Those will all be in a directories named after your account. E.g., – bahamat Aug 22 '11 at 17:20
Worked a treat. Thanks. Sorry about the confusion, I had read a very similar solution on another site that would have had me delete the entire inbox. – Mahmoud Al-Qudsi Aug 23 '11 at 0:44

If the ~/Library/Mail/Envelope Index trick does not work, which it did not for me there are a number of other steps one can take to rebuild the mail search index, some outlined here:

  1. try mdimport -r /System/Library/Spotlight/Mail.mdimporter in the Terminal

  2. try sudo mdutil – E in the Terminal (admin password required), or via the Spotlight preferences, add the whole computer to the 'Privacy' list of excluded folders, then remove it; both actions will force a recalculation of the spotlight index

  3. in my case, all the above failed to do anything, and I got an error message when trying to change the Spotlight privacy settings, indicating my whole index was really messed up. The solution was to type the following in the Terminal:

    sudo mv /.Spotlight-V100 /Spotlight-V100-old

    and then restart the computer, to force a reindex of the machine. You can also then clean up the folder "Spotlight-V100-old" that will now appear on your hard drive.

    This third nuclear option also requires admin privileges.

share|improve this answer
this sudo mv /.Spotlight-V100 /Spotlight-V100-old help me a lot. thanks. – pkyeck Jan 7 '13 at 19:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .