Force Spotlight Indexing on macOS

With the release of High Sierra, I assume most Mac users had a chance to upgrade any number of drives to APFS from HFS+. Now you may have noticed it by now, but apparently High Sierra has shipped with some glitches in APFS related tools. My mdutil search has turned up “Index Enabled” for all of my drives, but the actual index had stopped updating since Public Beta.

Let’s eliminate the first possible cause. It is possible the spotlight indexing is simply disabled. Try out this command first on Terminal.

Check Spotlight status:
mdutil -s /

This command will check the status of Spotlight indexing on all drives. If you have a drive in mind that needs checking, simply replace “/” with the path to the volume. Otherwise, simply run the command. If, for some reasons, it returned indexing disabled, you can enable it with the following command.

Enable Spotlight:
sudo mdutil -i on /

Often, these aren’t the cases. Among all the drives I have, none of them showed up as indexing disabled. Even if it were, I doubt this would have solved the problem. After some research, I’ve managed to narrow down the suspects into 2; either the volume’s metadata (index) is corrupted, or permission setup is messed up. Let’s tackle the first problem. If the index is corrupted, all you have to do is rebuild it. Use the following command.

Erase and rebuild index: 
sudo mdutil -E /

This command will erase ALL INDEXES ON ALL DRIVES and then rebuilt them. Again, if you are interested in rebuilding only one drive of its index, simply replace “/“ with the drive path. (e.g. replace it with /Volumes/Macintosh HD). You can check the status of the indexing on activity monitor. Look for processes that bare md, such as mdworker. If there are multiple processes taking up CPU loads, it means indexing is still underway.

Now the second problem. If you were getting the results during the rebuild, but now completely no results after it is finished, it means file system permissions are at fault. Before you do anything, try running First Aid from Disk Utility. If that fixes the issue, you are lucky. Otherwise, right click on the volume, and click “Get Info”. At the bottom of the window, there is a sharing & permission section. You are supposed to have read & write access. And if the box for “ignore ownership on this volume” is already ticked, un-tick it and unmount the drive. Mount it again, and check the box. Try Spotlight again.

If that doesn’t fixes the issue, you will have to run chmod command on the volume to gain permissions. On GUI, however, you can easily make that happen with few clicks. Under the cog button, there is a menu to “apply to enclosed items”. It will take a moment, wait for it, unmount the drive and mount it again. Try Spotlight. If this still doesn’t fix the issue, you may want to try “ignore ownership on this volume” again.

As for what is actually causing this glitch, I haven’t had a chance to find out. I am merely guessing the introduction of APFS may be the cause behind it. After the upgrade to High Sierra, I’ve started seeing the problems on Spotlight. After the official release, I came to the conclusion Spotlight just stopped working on all of my drives. Rebuilding the index solved the problems on couple of them, but it didn’t do the trick on my portable drives, other than the fact that it revealed the potential permissions issue. FYI, Spotlight actively filter out the results that relate to files you don’t have access to. After the rebuilding index is complete, and no results are shown, it means you need to troubleshoot permissions.

What annoyed me even further is the fact that there is no direct way of monitor indexing, other than guessing it from activity monitor. Soon as I find out, I’ll update the post to cover that area.

Leave a comment