Getting started with self-hosted Meilisearch
This quick start walks you through installing Meilisearch, adding documents, and performing your first search.
To follow this tutorial you need:
TIP
Using Meilisearch Cloud? Check out the dedicated guide, Getting started with Meilisearch Cloud.
Setup and installation
First, you need to download and install Meilisearch. This command installs the latest Meilisearch version in your local machine:
# Install Meilisearch
curl -L https://install.meilisearch.com | sh
The rest of this guide assumes you are using Meilisearch locally, but you may also use Meilisearch over a cloud service such as Meilisearch Cloud.
Learn more about other installation options in the installation guide.
Running Meilisearch
Next, launch Meilisearch by running the following command in your terminal:
# Launch Meilisearch
./meilisearch --master-key="aSampleMasterKey"
NOTE
This tutorial uses aSampleMasterKey
as a master key, but you may change it to any alphanumeric string with 16 or more bytes. In most cases, one character corresponds to one byte.
You should see something like this in response:
888b d888 d8b 888 d8b 888
8888b d8888 Y8P 888 Y8P 888
88888b.d88888 888 888
888Y88888P888 .d88b. 888 888 888 .d8888b .d88b. 8888b. 888d888 .d8888b 88888b.
888 Y888P 888 d8P Y8b 888 888 888 88K d8P Y8b "88b 888P" d88P" 888 "88b
888 Y8P 888 88888888 888 888 888 "Y8888b. 88888888 .d888888 888 888 888 888
888 " 888 Y8b. 888 888 888 X88 Y8b. 888 888 888 Y88b. 888 888
888 888 "Y8888 888 888 888 88888P' "Y8888 "Y888888 888 "Y8888P 888 888
Database path: "./data.ms"
Server listening on: "localhost:7700"
You now have a Meilisearch instance running in your terminal window. Keep this window open for the rest of this tutorial.
NOTE
The above command uses the --master-key
configuration option to secure Meilisearch. Setting a master key is optional but strongly recommended in development environments. Master keys are mandatory in production environments.
To learn more about securing Meilisearch, refer to the security tutorial.
Add documents
In this quick start, you will search through a collection of movies.
To follow along, first click this link to download the file: movies.json. Then, move the downloaded file into your working directory.
NOTE
Meilisearch accepts data in JSON, NDJSON, and CSV formats.
Open a new terminal window and run the following command:
curl \
-X POST 'http://localhost:7700/indexes/movies/documents?primaryKey=id' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer aSampleMasterKey' \
--data-binary @movies.json
Meilisearch stores data in the form of discrete records, called documents. Each document is an object composed of multiple fields, which are pairs of one attribute and one value:
{
"attribute": "value"
}
Documents are grouped into collections, called indexes.
The previous command added documents from movies.json
to a new index called movies
. It also set id
as the primary key.
NOTE
Every index must have a primary key, an attribute shared across all documents in that index. If you try adding documents to an index and even a single one is missing the primary key, none of the documents will be stored.
If you do not explicitly set the primary key, Meilisearch infers it from your dataset.
After adding documents, you should receive a response like this:
{
"taskUid": 0,
"indexUid": "movies",
"status": "enqueued",
"type": "documentAdditionOrUpdate",
"enqueuedAt": "2021-08-11T09:25:53.000000Z"
}
Use the returned taskUid
to check the status of your documents:
curl \
-X GET 'http://localhost:7700/tasks/0' \
-H 'Authorization: Bearer aSampleMasterKey'
NOTE
Most database operations in Meilisearch are asynchronous. Rather than being processed instantly, API requests are added to a queue and processed one at a time.
If the document addition is successful, the response should look like this:
{
"uid": 0,
"indexUid": "movies",
"status": "succeeded",
"type": "documentAdditionOrUpdate",
"canceledBy": null,
"details":{
"receivedDocuments": 19547,
"indexedDocuments": 19547
},
"error": null,
"duration": "PT0.030750S",
"enqueuedAt": "2021-12-20T12:39:18.349288Z",
"startedAt": "2021-12-20T12:39:18.352490Z",
"finishedAt": "2021-12-20T12:39:18.380038Z"
}
If status
is enqueued
or processing
, all you have to do is wait a short time and check again. Proceed to the next step once the task status
has changed to succeeded
.
Search
Now that you have Meilisearch set up, you can start searching!
curl \
-X POST 'http://localhost:7700/indexes/movies/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer aSampleMasterKey' \
--data-binary '{ "q": "botman" }'
NOTE
This tutorial queries Meilisearch with the master key. In production environments, this is a security risk. Prefer using API keys to access Meilisearch's API in any public-facing application.
In the above code sample, the parameter q
represents the search query. This query instructs Meilisearch to search for botman
in the documents you added in the previous step:
{
"hits": [
{
"id": 29751,
"title": "Batman Unmasked: The Psychology of the Dark Knight",
"poster": "https://image.tmdb.org/t/p/w1280/jjHu128XLARc2k4cJrblAvZe0HE.jpg",
"overview": "Delve into the world of Batman and the vigilante justice tha",
"release_date": "2008-07-15"
},
{
"id": 471474,
"title": "Batman: Gotham by Gaslight",
"poster": "https://image.tmdb.org/t/p/w1280/7souLi5zqQCnpZVghaXv0Wowi0y.jpg",
"overview": "ve Victorian Age Gotham City, Batman begins his war on crime",
"release_date": "2018-01-12"
},
…
],
"estimatedTotalHits": 66,
"query": "botman",
"limit": 20,
"offset": 0,
"processingTimeMs": 12
}
By default, Meilisearch only returns the first 20 results for a search query. You can change this using the limit
parameter.
What's next?
You now know how to install Meilisearch, create an index, add documents, check the status of an asynchronous task, and make a search request.
If you'd like to search through the documents you just added using a clean browser interface rather than the terminal, you can do so with our built-in search preview. You can also learn how to quickly build a front-end interface of your own.
For a more advanced approach, consult the API reference.