First, you need to download and install Meilisearch. This command installs the latest Meilisearch version in your local machine:
Copy
# Install Meilisearchcurl -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.
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 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.
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:
Copy
{ "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.
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:
curl \ -X GET 'MEILISEARCH_URL/tasks/0' \ -H 'Authorization: Bearer aSampleMasterKey'
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.
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:
Copy
{ "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.
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.