Getting started with self-hosted Meilisearch
Learn how to install Meilisearch, index a dataset, and perform your first search.
This quick start walks you through installing Meilisearch, adding documents, and performing your first search.
To follow this tutorial you need:
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:
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:
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:
You now have a Meilisearch instance running in your terminal window. Keep this window open for the rest of this tutorial.
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.
Meilisearch accepts data in JSON, NDJSON, and CSV formats.
Open a new terminal window and run the following command:
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:
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.
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:
Use the returned taskUid
to check the status of your documents:
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:
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!
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:
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.
Was this page helpful?