Why self-host Meilisearch on a VPS
Meilisearch offers a "search-as-you-type" experience comparable to commercial solutions, but under an open-source licence and with minimal configuration: no esoteric analyzer tuning, sensible defaults, and a clear API. Self-hosting it on a VPS spares you the per-document and per-search billing of managed services like Algolia, while keeping your indexes and your product data on your own infrastructure. It is a particularly cost-effective choice for an e-commerce site, a blog or documentation: a single modest VPS serves hundreds of thousands of searches per day with very low latency. You control the API keys, the filterable attributes and relevance, and you can reindex at will with no quota constraints.
The concrete benefits of self-hosting Meilisearch
- Instant search under 50 ms with typo tolerance enabled by default.
- Minimal configuration: sensible relevance settings out of the box, up and running in a few minutes.
- Built-in filtering, facets, sorting and highlighting to build a complete search UI.
- Written in Rust: a reasonable memory footprint and high throughput even on a small VPS.
- A simple API with SDKs for most languages and ready-to-use front-end integrations.
- No cost per indexed document or per query, unlike managed search engines.
Hardware and software prerequisites
Meilisearch is frugal but loads part of its indexes into memory to stay fast. For an index of a few tens of thousands of documents, 1 to 2 GB of RAM is enough; for hundreds of thousands of documents with many filterable attributes, aim for 2 to 4 GB. The indexing phase is the most demanding on RAM and CPU, so allow some headroom for reindexing. One to two vCPUs are fine, and 20 to 40 GB of SSD covers the index and its snapshots. You will need Docker, a domain if you expose the API publicly, and a MEILI_MASTER_KEY without fail: without it, in production mode, the instance refuses to start to protect you from open access.
Deploy Meilisearch step by step
Provision the VPS and Docker
Install Docker and configure the firewall to open only 80 and 443. Create a DNS A record for recherche.mydomain.com pointing to the VPS IP.
Launch Meilisearch in production mode
Use the getmeili/meilisearch image. Set MEILI_ENV=production and MEILI_MASTER_KEY with a strong key (openssl rand -base64 32). Mount a volume on /meili_data to persist the indexes: volumes: - ./meili_data:/meili_data.
Manage the API keys
From the master key, generate scoped keys: a search key to expose on the front-end, and an admin key on the server side for indexing. Never expose the master key in the browser.
Configure the reverse proxy and TLS
Place Caddy in front of port 7700: recherche.mydomain.com { reverse_proxy localhost:7700 }. Caddy obtains the Let's Encrypt certificate automatically and encrypts all search traffic.
Index your data and tune relevance
Push your documents via the API or an SDK, then define the searchableAttributes, filterableAttributes and sortableAttributes as well as the rankingRules suited to your use case (e-commerce, docs, blog).
Enable snapshots and backup
Configure Meilisearch's regular snapshots or dumps and copy them to remote storage. In the event of an incident, a dump lets you rebuild the instance with its indexes and settings.
Keep the list of filterableAttributes to the strict minimum: each filterable attribute increases the index size and the indexing time. For a responsive search UI, connect the front-end directly to Meilisearch with a scoped "search" key (limited to certain indexes) rather than relaying every request through your backend, which removes a round trip and reduces perceived latency. During a bulk reindex, monitor the task via the /tasks API rather than blocking while you wait.