Enabling Dovecot Full‑Text Search with Solr: Setup, Querying, and Trade‑offs
Learn how to enable Dovecot’s Solr‑backed full‑text search, configure the plugin, test indexing and queries, and understand the operational trade‑offs.
30 Dec 2025, 13:46 UTC

Problem: Slow IMAP SEARCH on large mailboxes
When a Dovecot server must scan every message to satisfy a TEXT or HEADER SEARCH, CPU usage spikes and latency grows with mailbox size. Users notice delayed results, especially in shared or archive folders.
Thesis: Off‑load indexing to an external Solr instance via the fts_solr plugin keeps search responsive while moving the indexing workload away from the mail server.
Configuration Steps
- Install the Solr plugin package (usually dovecot-fts-solr) and ensure a Solr core named
dovecotis reachable athttp://solr-host:8983/solr/dovecot. - Edit
/etc/dovecot/conf.d/10-mail.conf(or a local override) and add the plugin to the mail_plugins line:mail_plugins = $mail_plugins fts fts_solr - Create a file
/etc/dovecot/conf.d/20-fts_solr.confwith:plugin { fts = solr fts_solr_url = http://solr-host:8983/solr/dovecot fts_solr_timeout = 5 # Index Subject, From, To, Body fts_solr_fields = subject from to body } - Restart Dovecot:
sudo systemctl restart dovecot(requires root or sudo).
Indexing Workflow and Query Example
After restart, Dovecot indexes new messages as they are delivered. For a manual test you can inject a message with doveadm:
# Replace USER with a real account
sudo -u dovecot doveadm mailbox create -u USER Test
sudo -u dovecot doveadm save -u USER Test Then, from any IMAP client (or via telnet/openssl) log in and run:
a001 LOGIN USER password
a002 SEARCH TEXT \"Alpha\"
If indexing succeeded, the server returns a list of matching UIDs, e.g., * SEARCH 12345. The same query can be checked directly in Solr:
curl -s "http://solr-host:8983/solr/dovecot/select?q=Alpha&wt=json" | jq '.response.numFound'Trade‑offs and Limitations
- Operational dependency: If the Solr node is unreachable, Dovecot logs a warning and returns empty results for SEARCH; there is no automatic fallback to local scanning.
- Schema alignment: The fts_solr plugin expects fields named exactly as configured (subject, from, to, body) with text_general type. Changing the Solr schema requires matching those names and restarting Dovecot.
- Latency: Search latency now includes the network round‑trip to Solr plus Solr’s query time. For a local LAN this is usually
<10 ms, but a remote Solr cluster can add noticeable delay.
Verification and Next Steps
- Check Dovecot logs after restart for lines like
fts_solr: connected to Solr at http://solr-host:8983/solr/dovecot. - Use telnet or openssl to connect to the IMAP port, log in, and issue
SEARCH TEXT \"test\"; a non‑empty UID list confirms end‑to‑end flow. - Query Solr directly (as shown above) to verify that the document sent by Dovecot appears in the index.
- Monitor CPU usage on the Dovecot host before and after enabling fts_solr (e.g., with
toporpidstat) to observe the expected reduction.
Once verified, you can adjust fts_solr_timeout or tune Solr’s heap and commit settings to balance freshness versus load. Remember to include the Solr host in your monitoring and alerting so search failures are caught early.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.