Spotlight re-indexing takes too long or doesn't work
Issue
After forcing Spotlight to reindex, no files or directories can be found.
Setup
I've got a MacBook Pro 15" 2017 with a 512 GB SSD: 250 GB main volume (36 free) and a BOOTCAMP partition (not indexed), running macOS High Sierra (10.13.6). The file system is APFS.
How it happened
I wanted to force a Spotlight re-indexing (because a file, that was definitely in place, was missing in Search), so I added the whole volume to System Preferences -> Spotlight -> Privacy, and then removed it from there (Apple Support link), which should've caused a full Spotlight reindex. It did. a bunch of mdworker
processes appeared and started consuming CPU time and reading stuff from disk (which is expected).
Then they stopped. They are still there but they don't seem to be doing anything judging by the CPU load / disk usage stats.
And yet, now I can't find ANY files. Spotlight doesn't output any files / directories at all. It only outputs other stuff like visited emails, Dictionary suggestions, etc. Search (in Finder) doesn't work either.
What I tried:
-
Waiting for ~12 hours. I can't believe indexing ~220 Gb of content on a 3Gb/s SSD takes so long. Especially considering the zero CPU load.
-
Rebooting the mac (didn't help) and repeating the whole sequence again, waiting a few seconds before removing the disk from "Privacy" and waiting for quite a long time again.
-
running
sudo mdutil -E /
with the same effect as before (high CPU load -> no CPU load -> nothing is indexed).
By the way, running mdutil -s /
returns Indexing enabled.
There's no "Indexing" bar in my Spotlight window, if that's important.
Questions
Is there anything else I could try other than waiting for the problem to solve itself or updating to Mojave? Maybe there are more verbose Spotlight logs somewhere or something?
Possibly related question (no answer): Spotlight borked after macOS Sierra update (AskDifferent).
Solution 1:
OK, I solved it, it seems...
The Solution
Run
sudo /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -seed -lint -r -f -v -dump -domain local -domain system -domain user -domain network
killall Dock
sudo mdutil -E /
Not sure if all of these are needed, but that's what worked for me. The first command resets the Launch Sservices Database, the second one resets the Dock, and the third one triggers Spotlight reindexing.
Note that before that I tried running
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user
instead of the first command, and it didn't help. To be more precise, it seemed to have fixed search, but not spotlight.
I also tried sudo rm -R .Spotlight-V100/
suggested in the comments to the question, but it didn't help either.
Details
the issue was in the Launch Services Database. I figured it out by looking at the Console app. There were tons of messages like
errore 16:19:03.743202 +0100 mds LaunchServices: store or url (null) was nil -10813, retrying
errore 16:19:03.743247 +0100 mds LaunchServices: Database mapping failed with result -10813, retries = 7
I found this thread, which led me to trying to reset the Launch Services Database. First I tried the command above that failed. Then I found a fuller (it seems) version of that command, which is posted in the first code block in the "Solution" section above.