MainSDK
Search⌘K
Integrations

Meilisearch

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

1 interface1 driverWritten guide
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. 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.

Interfaces it serves

Pick Meilisearch in main.yaml for any of these. Your calls stay the same, and you can swap later.

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

main.yaml
search:
  driver: meilisearch
  # key: secret:MEILISEARCH_API_KEY   # suggested name; host and index keys are [to be decided]

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

Use it

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 without leaking another customer's records.

See Search and vector 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.
  • Backups of a self-hosted instance are yours to run; you can always rebuild an index from your records in db.

Swap to or from it

main.yaml
search:
  driver: meilisearch   # was algolia

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

Was this page helpful?

↑↓ moveEnter openEsc close

Not decided yet