Sub topic 13
When results are missing: checking and rebuilding the index
This chapter assumes you know how to open Spotlight, search for files, and run basic commands in Terminal. It also assumes you know what the Spotlight index is: a database of file names, contents, and metadata that macOS keeps so searches return instantly. If a file exists but Spotlight cannot find it, the index is usually the cause.
Why results go missing
Spotlight searches the index, not the disk. A file is missing from results when the index is out of date or when Spotlight was told to skip it. The common causes are:
- The folder or drive is listed under Spotlight's Search Privacy settings.
- The file's category is switched off in the Spotlight results settings.
- Indexing is turned off for the volume.
- The index is stale or damaged, often after a macOS update, a restore from backup, or a crash.
- Indexing is still running, for example just after you connect a new drive.
Check these causes in order, from cheapest to most disruptive.
Step 1: Check the settings
Open System Settings, choose Spotlight, and look at two places.
- Under Search Results, confirm the category you expect (for example Documents or PDF Documents) is ticked.
- Open Search Privacy and confirm the folder or drive holding your file is not in the list. Anything listed there is excluded from the index. Remove it with the minus button to have it indexed again.
Step 2: Check indexing status
The mdutil tool reports whether indexing is on for a volume. This command checks the startup volume:
mdutil -s /The output should say Indexing enabled. If it says Indexing disabled., turn it on with sudo mdutil -i on /. If Spotlight shows a progress bar or "Indexing..." when you open it, wait. Searches are incomplete until it finishes, and a large disk can take hours.
For an external drive, give its mount point instead of /:
mdutil -s /Volumes/BackupStep 3: Rebuild the index
If settings and status look right and the file is still missing, erase the index so macOS builds a new one:
sudo mdutil -E /The -E option erases the index for that volume. Spotlight then re-indexes in the background. Expect higher CPU use and fan noise for a while, and incomplete results until it finishes. Your files are not touched, only the search database.
You can also rebuild through System Settings by adding your disk to Search Privacy and then removing it. This forces a fresh index without Terminal.
Step 4: Confirm the fix
Once indexing finishes, test with a file you know exists. From Terminal, mdfind -name queries the same index:
mdfind -name "invoice"If Terminal finds the file but the Spotlight window does not, the problem is a result-category setting, not the index. If neither finds it, check the file's metadata:
mdls ~/Documents/report.pdfIf mdls prints only a few attributes, such as the name and dates, and no content type, the file has not been indexed. Common reasons are that the file sits in an excluded folder, on a volume with indexing off, or in a location Spotlight never indexes, such as system folders.
Quick reference
| Symptom | Likely cause | Action |
|---|---|---|
| Whole folder never appears | Listed in Search Privacy | Remove it from the list |
| One file type never appears | Category switched off | Tick it under Search Results |
| `Indexing disabled.` | Indexing off for the volume | `sudo mdutil -i on /` |
| Results incomplete, "Indexing..." shown | Index still building | Wait |
| Everything stale after an update or restore | Damaged index | `sudo mdutil -E /` |
Exercise
Spotlight shows no PDFs. mdutil -s / says "Indexing enabled." and mdfind -name "report" finds a PDF named report.pdf. What should you check first, and why is rebuilding the index not the right first step?
Show answer
Check Spotlight's Search Results settings and make sure PDF Documents is ticked. Because mdfind finds the file, the file is in the index, so the index is working. A rebuild would take hours and would not fix a category that is switched off.
Exercise
Write the command to check indexing on an external drive mounted at /Volumes/Photos, and the command to erase and rebuild its index.
Show answer
Check with mdutil -s /Volumes/Photos. Rebuild with sudo mdutil -E /Volumes/Photos.