---
title: "Meilisearch"
description: "Use Meilisearch for MainSDK search - self-hosted or cloud, API keys, main.yaml, indexing, results scoped to the searcher, testing and swapping."
section: "integrations"
canonical: "https://mainsdk.dev/docs/integrations/meilisearch"
updated: "2026-10-28"
---

# Meilisearch

> Use Meilisearch for MainSDK search - self-hosted or cloud, API keys, main.yaml, indexing, results scoped to the searcher, testing and swapping.

Canonical: https://mainsdk.dev/docs/integrations/meilisearch · Updated: 2026-10-28

Meilisearch is an open-source search engine you can run yourself or use as a hosted cloud service, and a driver behind [`search`](https://mainsdk.dev/docs/interfaces/search). Your app indexes records with `search.index()` and queries them with `search.query({ for: user })`, and MainSDK limits results to what the person searching may see. Pick Meilisearch when you want typo-tolerant search you can self-host in the region your data must stay in.

> **Note:** `search` has no spec yet. The calls and options on this page are provisional, taken from the catalog and the product requirements, and may change when the spec lands.

## Interfaces it serves

### Search (`search`)

- Status: Building for 0.4 · ships as a beta API
- Driver: `meilisearch` (Meilisearch)
- Docs: https://mainsdk.dev/docs/interfaces/search.md

```yaml
search:
  driver: meilisearch
```

Swap to another provider: `db`, `typesense`, `local`, `algolia`, `pgvector`.

## Before you start

1. **Run Meilisearch.** Self-host it on your own servers or a container platform, or create a project on Meilisearch Cloud. Place it in the region your records belong to.
2. **Set a master key.** A self-hosted instance in production needs one; Meilisearch uses it to protect the instance and to derive API keys.
3. **Create an API key for the app** with only the actions and indexes it needs, rather than using the master key.

Store the key in your secrets manager, never in code or a committed env file.

## Configure

```yaml title="main.yaml"
search:
  driver: meilisearch
  # key: secret:MEILISEARCH_API_KEY   # suggested name; host and index keys are [TBD]
```

Not decided yet: index names and fields, the document shape `search.index()` takes, and the connection settings per driver.

## Use it

```ts title="lib/products.ts"
import { search } from "mainsdk";

export async function onProductSaved(product: { id: string; name: string; description: string }) {
  await search.index(product);
}

export async function findProducts(q: string, user: { id: string }) {
  return search.query({ q, for: user, limit: 20 });
}
```

## Local development and testing

- **Locally:** run Meilisearch on your machine or in a container and point your development overlay at it.
- **Tests:** a `search` fake for `createTestApp()` from `@mainsdk/testing` arrives with the spec, along with `chaos.on("search", { outage: true })`. Write the test that proves a user never gets another user's records as soon as it exists.

## What MainSDK adds on top

- Results scoped to the person searching (`for: user`).
- The same `search.index()` and `search.query()` calls on every engine, so moving engines is one line plus a re-index.
- Hits that can ground an AI answer through [`ai`](https://mainsdk.dev/docs/interfaces/ai) without leaking another customer's records.

See [Search and vector search](https://mainsdk.dev/docs/interfaces/search) for the full contract.

## Limits and notes

- `meilisearch` is a planned `search` driver for phase 2, and `search` has no spec yet.
- An index is a copy of your data. Keep `personal` and `sensitive` fields out of it unless the feature needs them, and keep the instance in the right region: US, EU or India. See [Data and regions](https://mainsdk.dev/docs/concepts/data-and-regions).
- Backups of a self-hosted instance are yours to run; you can always rebuild an index from your records in [`db`](https://mainsdk.dev/docs/interfaces/db).

## Swap to or from it

```yaml title="main.yaml"
search:
  driver: meilisearch   # was algolia
```

> **Warning:** An index lives in the engine. Moving engines means re-indexing your records in the new one before you switch queries over.

## FAQ

**Self-hosted or cloud?** Both use the same driver. Self-host when you need the index in a region or network you control.

**Do I need the master key in my app?** No. Create an API key with only the rights the app needs.

## Next

- [Search and vector search](https://mainsdk.dev/docs/interfaces/search)
- [Typesense](https://mainsdk.dev/docs/integrations/typesense), [Algolia](https://mainsdk.dev/docs/integrations/algolia) and [Postgres](https://mainsdk.dev/docs/integrations/postgres)
- [Swap a driver](https://mainsdk.dev/docs/guides/swap-a-driver)
