Meilisearch
Use Meilisearch for MainSDK search - self-hosted or cloud, API keys, main.yaml, indexing, results scoped to the searcher, testing and swapping.
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.
searchBuilding for 0.4Driver meilisearch Meilisearch
search:
driver: meilisearchBefore you start
- 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.
- Set a master key. A self-hosted instance in production needs one; Meilisearch uses it to protect the instance and to derive API keys.
- 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
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
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
searchfake forcreateTestApp()from@mainsdk/testingarrives with the spec, along withchaos.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()andsearch.query()calls on every engine, so moving engines is one line plus a re-index. - Hits that can ground an AI answer through
aiwithout leaking another customer's records.
See Search and vector search for the full contract.
Limits and notes
meilisearchis a plannedsearchdriver for phase 2, andsearchhas no spec yet.- An index is a copy of your data. Keep
personalandsensitivefields 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
search:
driver: meilisearch # was algoliaFAQ
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?