Skip to main content
This guide walks you through adding documents to Meilisearch for the first time. You will prepare a dataset, send it to an index, monitor the indexing task, and verify the documents are searchable.

Prepare your documents

Meilisearch accepts documents in three formats: JSON, NDJSON, and CSV. Each document must contain a field that serves as a unique primary key. Here is a small sample dataset of movies in JSON format:
[
  {
    "id": 1,
    "title": "Carol",
    "genres": ["Romance", "Drama"],
    "year": 2015
  },
  {
    "id": 2,
    "title": "Wonder Woman",
    "genres": ["Action", "Adventure"],
    "year": 2017
  },
  {
    "id": 3,
    "title": "Life of Pi",
    "genres": ["Adventure", "Drama"],
    "year": 2012
  },
  {
    "id": 4,
    "title": "Mad Max: Fury Road",
    "genres": ["Action", "Adventure"],
    "year": 2015
  }
]
In this dataset, id is the primary key. Meilisearch automatically infers the primary key if a field is named id. If your primary key has a different name, you must specify it when adding documents.

Send documents to an index

Use the POST /indexes/{index_uid}/documents endpoint to add documents. If the index does not exist yet, Meilisearch creates it automatically. For a large dataset stored in a file:
curl \
  -X POST 'MEILISEARCH_URL/indexes/movies/documents?primaryKey=id' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer aSampleMasterKey' \
  --data-binary @movies.json
For a small number of documents sent inline:
curl \
  -X POST 'MEILISEARCH_URL/indexes/movies/documents' \
  -H 'Content-Type: application/json' \
  --data-binary '[
    {
      "id": 287947,
      "title": "Shazam",
      "poster": "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg",
      "overview": "A boy is given the ability to become an adult superhero in times of need with a single magic word.",
      "release_date": "2019-03-23"
    }
  ]'
Meilisearch returns a summarized task object confirming your request has been accepted:
{
  "taskUid": 0,
  "indexUid": "movies",
  "status": "enqueued",
  "type": "documentAdditionOrUpdate",
  "enqueuedAt": "2024-08-11T09:25:53.000000Z"
}

Check the task status

All indexing operations in Meilisearch are asynchronous. Use the taskUid from the response to check whether your documents have been indexed:
curl \
  -X GET 'MEILISEARCH_URL/tasks/0' \
  -H 'Authorization: Bearer aSampleMasterKey'
A successful task returns a status of succeeded:
{
  "uid": 0,
  "indexUid": "movies",
  "status": "succeeded",
  "type": "documentAdditionOrUpdate",
  "details": {
    "receivedDocuments": 4,
    "indexedDocuments": 4
  }
}
If the status is failed, the response includes an error object explaining what went wrong.

Verify documents are searchable

Once the task succeeds, your documents are ready to search. Test with a simple query:
curl \
  -X POST 'MEILISEARCH_URL/indexes/movies/search' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer MEILISEARCH_KEY' \
  --data-binary '{ "q": "wonder" }'
You should see “Wonder Woman” in the results.

Accepted document formats

FormatContent-Type headerNotes
JSONapplication/jsonArray of objects. Most common format.
NDJSONapplication/x-ndjsonOne JSON object per line. Useful for streaming large datasets.
CSVtext/csvFirst row must be column headers. All values are strings by default.

Next steps

Monitor tasks

Track and manage asynchronous indexing operations

Add and update documents

Learn the difference between replacing and partially updating documents

Indexing overview

Understand how indexing works in Meilisearch

Best practices

Optimize your indexing performance