Every unique search on your store is saved in the search_query table, forever. That includes the endless one-off strings bots type into search boxes. Nothing in Magento prunes it.
Why it matters
- Search suggestions (autocomplete) read this table, so a bloated table makes the suggestion dropdown slower for every shopper.
- The admin Search Terms grid becomes slow to open.
- It wastes database space and slows backups.
Check the size
SELECT COUNT(*) AS total,
SUM(popularity = 1 AND updated_at < DATE_SUB(NOW(), INTERVAL 90 DAY)) AS one_time_old
FROM search_query;
On many stores, most rows are searches made exactly once, months ago.
Clean it safely
Delete searches made only once, more than 90 days ago, in batches during a quiet time:
DELETE FROM search_query
WHERE popularity = 1
AND updated_at < DATE_SUB(NOW(), INTERVAL 90 DAY)
LIMIT 50000;
Repeat until 0 rows are affected, then refresh the suggestions cache:
bin/magento cache:clean
What this keeps
Terms searched more than once are never touched, so popular searches and any redirects or synonyms you set up for them stay. If you use search terms for merchandising reports, back up the table first. The deleted one-time searches are gone for good.
Catch it automatically
MageMonitor checks for this every few minutes as part of its Search checks, and alerts you by email, Slack or webhook the moment it appears, with the exact commands to fix it. See MageMonitor for Magento 2.
