Search with Meilisearch
Search with Meilisearch
Meilisearch is a lightning-fast search engine with typo tolerance. It is designed to feel instant: results come back in milliseconds, typos are forgiven, and ranking happens out of the box. A Meilisearch service gives you a managed instance of the engine that sits inside your application and is reachable over HTTP.
Good fits for it:
- Full-text search across articles, posts or any large collection of text
- Product search that has to survive misspelled queries and return fast
- Documentation or knowledge-base search
- Instant search-as-you-type suggestions for a search box
Adding it
- Open your application and go to Custom services.
- Click Create service and pick Meilisearch.
- Choose a version. v1.32 is the default, with v1.31, v1.30, v1.29 and v1.28 also available.
- Choose how much memory and storage it gets. It keeps its data on a persistent 10GB volume mounted at
/meili_data, so your indexes survive restarts.
That is all you need to get it running.
Environment variables
Once the service is live, your application gets the following variables injected. They appear in your deployment the next time it runs.
- MEILISEARCH_URL is
http://HOST:7700, the full base URL of the service - MEILISEARCH_HOST is
http://HOST:7700, the same address - MEILISEARCH_PORT is
7700 - MEILISEARCH_KEY is the master key that secures the service
- MEILI_MASTER_KEY is an alternative name for the same master key
The master key is generated for you, 64 characters long, when the service is created. Because it is generated, it is not something you set and it is not shown as a field. Point your search client at MEILISEARCH_HOST and send MEILISEARCH_KEY as the Authorization: Bearer header, and you have everything you need.
Configuration
Under Service configuration and Advanced settings you can adjust two settings:
- MEILI_ENV is the environment the engine runs in. The default is
production, which is what you want for a live instance. - MEILI_LOG_LEVEL controls how much the engine logs. The default is
INFO.
Saving a changed setting restarts the service, so anything in flight at that moment is dropped. Doing it during a quiet moment is worth keeping in mind.
Searching from your application
The HTTP API is the simplest way to talk to the service. Using MEILISEARCH_HOST for the address and MEILISEARCH_KEY for the master key, create an index and push a document:
curl -X POST "$MEILISEARCH_HOST/indexes/movies/documents" \
-H "Authorization: Bearer $MEILISEARCH_KEY" \
-H "Content-Type: application/json" \
--data '[
{ "id": 1, "title": "Botany of Desire", "genre": "documentary" },
{ "id": 2, "title": "The Grand Budapest Hotel", "genre": "comedy" }
]'
Then search it. Meilisearch handles the typing for you, so a misspelled query still matches:
curl "$MEILISEARCH_HOST/indexes/movies/search" \
-H "Authorization: Bearer $MEILISEARCH_KEY" \
--data-urlencode "q=grand budpest"
The same endpoints are what most language SDKs wrap, so if your application already uses a Meilisearch client you only need to give it the host and key above and it works unchanged.