Documents
Documents are objects composed of fields that can store any type of data.
Each field contains an attribute and its associated value.
Documents are stored inside indexes.
Learn more about documents.
Get one document
GET
/indexes/:index_uid/documents/:document_id
Get one document using its unique id.
Path variables
Variable | Description |
---|---|
index_uid | The index UID |
document_id | The document id |
Example
cURL
JavaScript
Python
PHP
Ruby
Go
Rust
curl \
-X GET 'http://localhost:7700/indexes/movies/documents/25684'
client.getDocument(25684)
client.index('movies').get_document(25684)
$client->index('movies')->getDocument(25684);
client.index('movies').document(25684)
var a interface{}
client.Index("movies").GetDocument("25684", &a)
let movie: Movie = movies.get_document(String::from("25684")).await.unwrap();
Response: 200 Ok
{
"id": 25684,
"title": "American Ninja 5",
"poster": "https://image.tmdb.org/t/p/w1280/iuAQVI4mvjI83wnirpD8GVNRVuY.jpg",
"overview": "When a scientists daughter is kidnapped, American Ninja, attempts to find her, but this time he teams up with a youngster he has trained in the ways of the ninja.",
"release_date": "1993-01-01"
}
Get documents
GET
/indexes/:index_uid/documents
Get documents by batch.
Using the query parameters offset
and limit
, you can browse through all your documents.
NOTE
Documents are ordered by MeiliSearch depending on the hash of their id.
Path variables
Variable | Description |
---|---|
index_uid | The index UID |
Query parameters
Query Parameter | Description | Default Value |
---|---|---|
offset | number of documents to skip | 0 |
limit | number of documents to take | 20 |
attributesToRetrieve | document attributes to show | * |
Example
cURL
JavaScript
Python
PHP
Ruby
Go
Rust
curl \
-X GET 'http://localhost:7700/indexes/movies/documents?limit=2'
client.index('movies').getDocuments({ limit: 2 })
client.index('movies').get_documents({'limit':2})
$client->index('movies')->getDocuments(['limit' => 2]);
client.index('movies').documents(limit: 2)
var a []interface{}
client.Index("movies").GetDocuments(&meilisearch.DocumentsRequest{
Limit: 2,
}, &a)
let documents: Vec<Movie> = movies.get_documents(None, Some(2), None).await.unwrap();
Response: 200 Ok
[
{
"id": 25684,
"release_date": "1993-01-01",
"poster": "https://image.tmdb.org/t/p/w1280/iuAQVI4mvjI83wnirpD8GVNRVuY.jpg",
"title": "American Ninja 5",
"overview": "When a scientists daughter is kidnapped, American Ninja, attempts to find her, but this time he teams up with a youngster he has trained in the ways of the ninja."
},
{
"id": 468219,
"title": "Dead in a Week (Or Your Money Back)",
"release_date": "2018-09-12",
"poster": "https://image.tmdb.org/t/p/w1280/f4ANVEuEaGy2oP5M0Y2P1dwxUNn.jpg",
"overview": "William has failed to kill himself so many times that he outsources his suicide to aging assassin Leslie. But with the contract signed and death assured within a week (or his money back), William suddenly discovers reasons to live... However Leslie is under pressure from his boss to make sure the contract is completed."
}
]
Add or replace documents
POST
/indexes/:index_uid/documents
Add a list of documents or replace them if they already exist. If the provided index does not exist, it will be created.
If you send an already existing document (same documentId) the whole existing document will be overwritten by the new document. Fields previously in the document not present in the new document are removed.
For a partial update of the document see add or update documents.
If the provided index does not exist, it will be created.
Path variables
Variable | Description |
---|---|
index_uid | The index UID |
Query parameters
Query Parameter | Description | Default Value |
---|---|---|
primaryKey | The primary key of the documents (optional) | none |
If you want to set the primary key of your index through this route, it only has to be done the first time you add documents to the index. After which it will be ignored if given.
Body
The body is composed of a JSON array of documents.
[
{
"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"
}
]
Example
cURL
JavaScript
Python
PHP
Ruby
Go
Rust
curl \
-X POST 'http://localhost:7700/indexes/movies/documents' \
--data '[{
"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"
}]'
client.index('movies').addDocuments([{
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'
}])
client.index('movies').add_documents([{
'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'
}])
$client->index('movies')->addDocuments([
[
'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'
]
]);
client.index('movies').add_documents([
{
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'
}
])
documents := []map[string]interface{}{
{
"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",
},
}
client.Index("movies").AddDocument(documents)
let progress: Progress = movies.add_or_replace(&[
Movie {
id: 287947,
title: "Shazam".to_string(),
poster: "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg".to_string(),
overview: "A boy is given the ability to become an adult superhero in times of need with a single magic word.".to_string(),
release_date: "2019-03-23".to_string(),
}
], None).await.unwrap();
Response: 202 Accepted
{
"updateId": 1
}
This updateId
allows you to track the current update.
Add or update documents
PUT
/indexes/:index_uid/documents
Add a list of documents or update them if they already exist. If the provided index does not exist, it will be created.
If you send an already existing document (same documentId) the old document will be only partially updated according to the fields of the new document. Thus, any fields not present in the new document are kept and remained unchanged.
To completely overwrite a document, check out the add or replace documents route.
If the provided index does not exist, it will be created.
Path variables
Variable | Description |
---|---|
index_uid | The index UID |
If you want to set the primary key of your index through this route, it only has to be done the first time you add documents to the index. After which it will be ignored if given.
Query parameters
Query Parameter | Description | Default Value |
---|---|---|
primaryKey | The primary key of the documents (optional) | none |
Body
The body is composed of a JSON array of documents.
[
{
"id": 287947,
"title": "Shazam ⚡️"
}
]
Example
cURL
JavaScript
Python
PHP
Ruby
Go
Rust
curl \
-X PUT 'http://localhost:7700/indexes/movies/documents' \
--data '[{
"id": 287947,
"title": "Shazam ⚡️",
"genres": "comedy"
}]'
client.index('movies').updateDocuments([{
id: 287947,
title: 'Shazam ⚡️',
genres: 'comedy'
}])
client.index('movies').update_documents([{
'id': 287947,
'title': 'Shazam ⚡️',
'genres': 'comedy'
}])
$client->index('movies')->updateDocuments([
[
'id' => 287947
'title' => 'Shazam ⚡️',
'genres' => 'comedy'
]
]);
client.index('movies').update_documents([
{
id: 287947,
title: 'Shazam ⚡️',
genres: 'comedy'
}
])
documents := []map[string]interface{}{
{
"id": 287947,
"title": "Shazam ⚡️",
"genres": "comedy",
},
}
client.Index("movies").UpdateDocuments(documents)
// Define the type of our documents
#[derive(Serialize, Deserialize, Debug)]
struct IncompleteMovie {
id: usize,
title: String
}
impl Document for IncompleteMovie {
type UIDType = usize;
fn get_uid(&self) -> &Self::UIDType { &self.id }
}
let progress: Progress = movies.add_or_update(&[
IncompleteMovie {
id: 287947,
title: "Shazam ⚡️".to_string()
}
], None).await.unwrap();
This document is an update of the document found in add or replace document.
The documents are matched because they have the same primaryKey
value id: 287947
. This route will update the title
field as it changed from Shazam
to Shazam ⚡️
and add the new genres
field to that document. The rest of the document will remain unchanged.
Response: 202 Accepted
{
"updateId": 1
}
This updateId
allows you to track the current update.
Delete all documents
DELETE
/indexes/:index_uid/documents
Delete all documents in the specified index.
Path variables
Variable | Description |
---|---|
index_uid | The index UID |
Example
cURL
JavaScript
Python
PHP
Ruby
Go
Rust
curl \
-X DELETE 'http://localhost:7700/indexes/movies/documents'
client.index('movies').deleteAllDocuments()
client.index('movies').delete_all_documents()
$client->index('movies')->deleteAllDocuments();
client.index('movies').delete_all_documents
client.Index("movies").DeleteAllDocuments()
let progress: Progress = movies.delete_all_documents().await.unwrap();
Response: 202 Accepted
{
"updateId": 1
}
This updateId
allows you to track the current update.
Delete one document
DELETE
/indexes/:index_uid/documents/:document_id
Delete one document based on its unique id.
Path variables
Variable | Description |
---|---|
index_uid | The index UID |
document_id | The document id |
Example
cURL
JavaScript
Python
PHP
Ruby
Go
Rust
curl \
-X DELETE 'http://localhost:7700/indexes/movies/documents/25684'
client.index('movies').deleteDocument(25684)
client.index('movies').delete_document(25684)
$client->index('movies')->deleteDocument(25684);
client.index('movies').delete_document(25684)
client.Index("movies").DeleteDocument("25684")
let progress: Progress = movies.delete_document(25684).await.unwrap();
Response: 202 Accepted
{
"updateId": 1
}
This updateId
allows you to track the current update.
Delete documents
POST
/indexes/:index_uid/documents/delete-batch
Delete a selection of documents based on array of document id’s.
Path variables
Variable | Description |
---|---|
index_uid | The index UID |
Body
The body must be a JSON Array with the unique id’s of the documents to delete.
[23488, 153738, 437035, 363869]
Example
cURL
JavaScript
Python
PHP
Ruby
Go
Rust
curl \
-X POST 'http://localhost:7700/indexes/movies/documents/delete-batch' \
--data '[
23488,
153738,
437035,
363869
]'
client.index('movies').deleteDocuments([23488, 153738, 437035, 363869])
client.index('movies').delete_documents([23488, 153738, 437035, 363869])
$client->index('movies')->deleteDocuments([23488, 153738, 437035, 363869]);
client.index('movies').delete_documents([23488, 153738, 437035, 363869])
client.Index("movies").DeleteDocuments([]string{
"23488",
"153738",
"437035",
"363869",
})
let progress: Progress = movies.delete_documents(&[23488, 153738, 437035, 363869]).await.unwrap();
Response: 202 Accepted
{
"updateId": 1
}
This updateId
allows you to track the current update.