pub struct Index {
    pub client: Client,
    pub uid: String,
    pub updated_at: Option<OffsetDateTime>,
    pub created_at: Option<OffsetDateTime>,
    pub primary_key: Option<String>,
}
Expand description

A Meilisearch index.

§Example

You can create an index remotely and, if that succeed, make an Index out of it. See the Client::create_index method.


// get the index called movies or create it if it does not exist
let movies = client
    .create_index("index", None)
    .await
    .unwrap()
    // We wait for the task to execute until completion
    .wait_for_completion(&client, None, None)
    .await
    .unwrap()
    // Once the task finished, we try to create an `Index` out of it
    .try_make_index(&client)
    .unwrap();

assert_eq!(movies.as_ref(), "index");

Or, if you know the index already exist remotely you can create an Index with its builder.


// Meilisearch would be able to create the index if it does not exist during:
// - the documents addition (add and update routes)
// - the settings update
let movies = Index::new("movies", client);

assert_eq!(movies.uid, "movies");

Fields§

§client: Client§uid: String§updated_at: Option<OffsetDateTime>§created_at: Option<OffsetDateTime>§primary_key: Option<String>

Implementations§

source§

impl Index

source

pub fn new(uid: impl Into<String>, client: Client) -> Index

source

pub async fn update(&self) -> Result<TaskInfo, Error>

Update an Index.

§Example
index.primary_key = Some("special_id".to_string());
let task = index.update()
    .await
    .unwrap()
    .wait_for_completion(&client, None, None)
    .await
    .unwrap();

let index = client.get_index("index_update").await.unwrap();

assert_eq!(index.primary_key, Some("special_id".to_string()));
source

pub async fn delete(self) -> Result<TaskInfo, Error>

Delete the index.

§Example

// get the index named "movies" and delete it
let index = client.index("delete");
let task = index.delete().await.unwrap();

client.wait_for_task(task, None, None).await.unwrap();
source

pub async fn execute_query<T: 'static + DeserializeOwned>( &self, body: &SearchQuery<'_> ) -> Result<SearchResults<T>, Error>

Search for documents matching a specific query in the index.

See also Index::search.

§Example
#[derive(Serialize, Deserialize, Debug)]
struct Movie {
    name: String,
    description: String,
}
let movies = client.index("execute_query");

// add some documents

let query = SearchQuery::new(&movies).with_query("Interstellar").with_limit(5).build();
let results = movies.execute_query::<Movie>(&query).await.unwrap();

assert!(results.hits.len() > 0);
source

pub fn search(&self) -> SearchQuery<'_>

Search for documents matching a specific query in the index.

See also Index::execute_query.

§Example
#[derive(Serialize, Deserialize, Debug)]
struct Movie {
    name: String,
    description: String,
}

let mut movies = client.index("search");

let results = movies.search()
    .with_query("Interstellar")
    .with_limit(5)
    .execute::<Movie>()
    .await
    .unwrap();

assert!(results.hits.len() > 0);
source

pub async fn get_document<T: 'static + DeserializeOwned>( &self, document_id: &str ) -> Result<T, Error>

Get one document using its unique id.

Serde is needed. Add serde = {version="1.0", features=["derive"]} in the dependencies section of your Cargo.toml.

§Example
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct Movie {
    name: String,
    description: String
}

let movies = client.index("get_document");

// retrieve a document (you have to put the document in the index before)
let interstellar = movies.get_document::<Movie>("Interstellar").await.unwrap();

assert_eq!(interstellar, Movie {
    name: String::from("Interstellar"),
    description: String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage."),
});
source

pub async fn get_document_with<T: 'static + DeserializeOwned>( &self, document_id: &str, document_query: &DocumentQuery<'_> ) -> Result<T, Error>

Get one document with parameters.

§Example
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct MyObject {
    id: String,
    kind: String,
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct MyObjectReduced {
    id: String,
}

let mut document_query = DocumentQuery::new(&index);
document_query.with_fields(["id"]);

let document = index.get_document_with::<MyObjectReduced>("1", &document_query).await.unwrap();

assert_eq!(
    document,
    MyObjectReduced { id: "1".to_string() }
);
source

pub async fn get_documents<T: DeserializeOwned + 'static>( &self ) -> Result<DocumentsResults<T>, Error>

Get documents by batch.

§Example
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Movie {
    name: String,
    description: String,
}

let movie_index = client.index("get_documents");

// retrieve movies (you have to put some movies in the index before)
let movies = movie_index.get_documents::<Movie>().await.unwrap();

assert!(movies.results.len() > 0);
source

pub async fn get_documents_with<T: DeserializeOwned + 'static>( &self, documents_query: &DocumentsQuery<'_> ) -> Result<DocumentsResults<T>, Error>

Get documents by batch with parameters.

§Example
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Movie {
    name: String,
    description: String,
}

#[derive(Deserialize, Debug, PartialEq)]
struct ReturnedMovie {
    name: String,
}

let movie_index = client.index("get_documents_with");

let mut query = DocumentsQuery::new(&movie_index);
query.with_limit(1);
query.with_fields(["name"]);
// retrieve movies (you have to put some movies in the index before)
let movies = movie_index.get_documents_with::<ReturnedMovie>(&query).await.unwrap();

assert_eq!(movies.results.len(), 1);
source

pub async fn add_or_replace<T: Serialize>( &self, documents: &[T], primary_key: Option<&str> ) -> Result<TaskInfo, Error>

Add a list of documents or replace them if they already exist.

If you send an already existing document (same id) 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 Index::add_or_update.

You can use the alias Index::add_documents if you prefer.

§Example
#[derive(Serialize, Deserialize, Debug)]
struct Movie {
    name: String,
    description: String,
}

let movie_index = client.index("add_or_replace");

let task = movie_index.add_or_replace(&[
    Movie{
        name: String::from("Interstellar"),
        description: String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")
    },
    Movie{
        // note that the id field can only take alphanumerics characters (and '-' and '/')
        name: String::from("MrsDoubtfire"),
        description: String::from("Loving but irresponsible dad Daniel Hillard, estranged from his exasperated spouse, is crushed by a court order allowing only weekly visits with his kids. When Daniel learns his ex needs a housekeeper, he gets the job -- disguised as an English nanny. Soon he becomes not only his children's best pal but the kind of parent he should have been from the start.")
    },
    Movie{
        name: String::from("Apollo13"),
        description: String::from("The true story of technical troubles that scuttle the Apollo 13 lunar mission in 1971, risking the lives of astronaut Jim Lovell and his crew, with the failed journey turning into a thrilling saga of heroism. Drifting more than 200,000 miles from Earth, the astronauts work furiously with the ground crew to avert tragedy.")
    },
], Some("name")).await.unwrap();
// Meilisearch may take some time to execute the request so we are going to wait till it's completed
client.wait_for_task(task, None, None).await.unwrap();

let movies = movie_index.get_documents::<Movie>().await.unwrap();
assert!(movies.results.len() >= 3);
source

pub async fn add_or_replace_unchecked_payload<T: AsyncRead + Send + Sync + 'static>( &self, payload: T, content_type: &str, primary_key: Option<&str> ) -> Result<TaskInfo, Error>

Add a raw and unchecked payload to meilisearch.

This can be useful if your application is only forwarding data from other sources.

If you send an already existing document (same id) 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 Index::add_or_update_unchecked_payload.

§Example
let movie_index = client.index("add_or_replace_unchecked_payload");

let task = movie_index.add_or_replace_unchecked_payload(
    r#"{ "id": 1, "body": "doggo" }
    { "id": 2, "body": "catto" }"#.as_bytes(),
    "application/x-ndjson",
    Some("id"),
  ).await.unwrap();
// Meilisearch may take some time to execute the request so we are going to wait till it's completed
client.wait_for_task(task, None, None).await.unwrap();

let movies = movie_index.get_documents::<serde_json::Value>().await.unwrap();
assert_eq!(movies.results.len(), 2);
source

pub async fn add_documents<T: Serialize>( &self, documents: &[T], primary_key: Option<&str> ) -> Result<TaskInfo, Error>

source

pub async fn update_documents_ndjson<T: AsyncRead + Send + Sync + 'static>( &self, payload: T, primary_key: Option<&str> ) -> Result<TaskInfo, Error>

Add a raw ndjson payload and update them if they already.

It configures the correct content type for ndjson data.

If you send an already existing document (same id) 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 Index::add_documents_ndjson documents method.

§Example
let movie_index = client.index("update_documents_ndjson");

let task = movie_index.update_documents_ndjson(
    r#"{ "id": 1, "body": "doggo" }
    { "id": 2, "body": "catto" }"#.as_bytes(),
    Some("id"),
  ).await.unwrap();
// Meilisearch may take some time to execute the request so we are going to wait till it's completed
client.wait_for_task(task, None, None).await.unwrap();

let movies = movie_index.get_documents::<serde_json::Value>().await.unwrap();
assert_eq!(movies.results.len(), 2);
source

pub async fn add_documents_ndjson<T: AsyncRead + Send + Sync + 'static>( &self, payload: T, primary_key: Option<&str> ) -> Result<TaskInfo, Error>

Add a raw ndjson payload to meilisearch.

It configures the correct content type for ndjson data.

If you send an already existing document (same id) 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 Index::update_documents_ndjson.

§Example
let movie_index = client.index("add_documents_ndjson");

let task = movie_index.add_documents_ndjson(
    r#"{ "id": 1, "body": "doggo" }
    { "id": 2, "body": "catto" }"#.as_bytes(),
    Some("id"),
  ).await.unwrap();
// Meilisearch may take some time to execute the request so we are going to wait till it's completed
client.wait_for_task(task, None, None).await.unwrap();

let movies = movie_index.get_documents::<serde_json::Value>().await.unwrap();
assert_eq!(movies.results.len(), 2);
source

pub async fn update_documents_csv<T: AsyncRead + Send + Sync + 'static>( &self, payload: T, primary_key: Option<&str> ) -> Result<TaskInfo, Error>

Add a raw csv payload and update them if they already.

It configures the correct content type for csv data.

If you send an already existing document (same id) 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 Index::add_documents_csv documents method.

§Example
let movie_index = client.index("update_documents_csv");

let task = movie_index.update_documents_csv(
    "id,body\n1,\"doggo\"\n2,\"catto\"".as_bytes(),
    Some("id"),
  ).await.unwrap();
// Meilisearch may take some time to execute the request so we are going to wait till it's completed
client.wait_for_task(task, None, None).await.unwrap();

let movies = movie_index.get_documents::<serde_json::Value>().await.unwrap();
assert_eq!(movies.results.len(), 2);
source

pub async fn add_documents_csv<T: AsyncRead + Send + Sync + 'static>( &self, payload: T, primary_key: Option<&str> ) -> Result<TaskInfo, Error>

Add a raw csv payload to meilisearch.

It configures the correct content type for csv data.

If you send an already existing document (same id) 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 Index::update_documents_csv.

§Example
let movie_index = client.index("add_documents_csv");

let task = movie_index.add_documents_csv(
    "id,body\n1,\"doggo\"\n2,\"catto\"".as_bytes(),
    Some("id"),
  ).await.unwrap();
// Meilisearch may take some time to execute the request so we are going to wait till it's completed
client.wait_for_task(task, None, None).await.unwrap();

let movies = movie_index.get_documents::<serde_json::Value>().await.unwrap();
assert_eq!(movies.results.len(), 2);
source

pub async fn add_or_update<T: Serialize>( &self, documents: &[T], primary_key: Option<impl AsRef<str>> ) -> Result<TaskInfo, Error>

Add a list of documents and update them if they already.

If you send an already existing document (same id) 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 Index::add_or_replace documents method.

§Example
#[derive(Serialize, Deserialize, Debug)]
struct Movie {
    name: String,
    description: String,
}

let movie_index = client.index("add_or_update");

let task = movie_index.add_or_update(&[
    Movie {
        name: String::from("Interstellar"),
        description: String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")
    },
    Movie {
        // note that the id field can only take alphanumerics characters (and '-' and '/')
        name: String::from("MrsDoubtfire"),
        description: String::from("Loving but irresponsible dad Daniel Hillard, estranged from his exasperated spouse, is crushed by a court order allowing only weekly visits with his kids. When Daniel learns his ex needs a housekeeper, he gets the job -- disguised as an English nanny. Soon he becomes not only his children's best pal but the kind of parent he should have been from the start.")
    },
    Movie {
        name: String::from("Apollo13"),
        description: String::from("The true story of technical troubles that scuttle the Apollo 13 lunar mission in 1971, risking the lives of astronaut Jim Lovell and his crew, with the failed journey turning into a thrilling saga of heroism. Drifting more than 200,000 miles from Earth, the astronauts work furiously with the ground crew to avert tragedy.")
    },
], Some("name")).await.unwrap();

// Meilisearch may take some time to execute the request so we are going to wait till it's completed
client.wait_for_task(task, None, None).await.unwrap();

let movies = movie_index.get_documents::<Movie>().await.unwrap();
assert!(movies.results.len() >= 3);
source

pub async fn add_or_update_unchecked_payload<T: AsyncRead + Send + Sync + 'static>( &self, payload: T, content_type: &str, primary_key: Option<&str> ) -> Result<TaskInfo, Error>

Add a raw and unchecked payload to meilisearch.

This can be useful if your application is only forwarding data from other sources.

If you send an already existing document (same id) 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 Index::add_or_replace_unchecked_payload documents method.

§Example
let movie_index = client.index("add_or_replace_unchecked_payload");

let task = movie_index.add_or_update_unchecked_payload(
    r#"{ "id": 1, "body": "doggo" }
    { "id": 2, "body": "catto" }"#.as_bytes(),
    "application/x-ndjson",
    Some("id"),
).await.unwrap();
// Meilisearch may take some time to execute the request so we are going to wait till it's completed
client.wait_for_task(task, None, None).await.unwrap();

let movies = movie_index.get_documents::<serde_json::Value>().await.unwrap();

assert_eq!(movies.results.len(), 2);
source

pub async fn delete_all_documents(&self) -> Result<TaskInfo, Error>

Delete all documents in the Index.

§Example
let movie_index = client.index("delete_all_documents");
movie_index.delete_all_documents()
    .await
    .unwrap()
    .wait_for_completion(&client, None, None)
    .await
    .unwrap();
let movies = movie_index.get_documents::<Movie>().await.unwrap();
assert_eq!(movies.results.len(), 0);
source

pub async fn delete_document<T: Display>( &self, uid: T ) -> Result<TaskInfo, Error>

Delete one document based on its unique id.

§Example
let mut movies = client.index("delete_document");
// add a document with id = Interstellar
movies.delete_document("Interstellar")
    .await
    .unwrap()
    .wait_for_completion(&client, None, None)
    .await
    .unwrap();
source

pub async fn delete_documents<T: Display + Serialize + Debug>( &self, uids: &[T] ) -> Result<TaskInfo, Error>

Delete a selection of documents based on array of document id’s.

§Example
let movies = client.index("delete_documents");
// delete some documents
movies.delete_documents(&["Interstellar", "Unknown"])
    .await
    .unwrap()
    .wait_for_completion(&client, None, None)
    .await
    .unwrap();
source

pub async fn delete_documents_with( &self, query: &DocumentDeletionQuery<'_> ) -> Result<TaskInfo, Error>

Delete a selection of documents with filters.

§Example
let index = client.index("delete_documents_with");

let mut query = DocumentDeletionQuery::new(&index);
query.with_filter("id = 1");
// delete some documents
index.delete_documents_with(&query)
    .await
    .unwrap()
    .wait_for_completion(&client, None, None)
    .await
    .unwrap();
source

pub async fn set_primary_key( &mut self, primary_key: impl AsRef<str> ) -> Result<TaskInfo, Error>

Alias for the Index::update method.

source

pub async fn fetch_info(&mut self) -> Result<(), Error>

Fetch the information of the index as a raw JSON Index, this index should already exist.

If you use it directly from the Client, you can use the method Client::get_raw_index, which is the equivalent method from the client.

§Example
let mut idx = client.index("fetch_info");
idx.fetch_info().await.unwrap();

println!("{idx:?}");
source

pub async fn get_primary_key(&mut self) -> Result<Option<&str>, Error>

Fetch the primary key of the index.

§Example
let mut index = client.create_index("get_primary_key", Some("id"))
    .await
    .unwrap()
    .wait_for_completion(&client, None, None)
    .await.unwrap()
    .try_make_index(&client)
    .unwrap();

let primary_key = index.get_primary_key().await.unwrap();

assert_eq!(primary_key, Some("id"));
source

pub async fn get_task(&self, uid: impl AsRef<u32>) -> Result<Task, Error>

Get a Task from a specific Index to keep track of asynchronous operations.

§Example
let movies = client.index("get_task");

let task = movies.add_documents(&[
    Document { id: 0, kind: "title".into(), value: "The Social Network".to_string() }
], None).await.unwrap();

// Get task status from the index, using `uid`
let status = movies.get_task(&task).await.unwrap();

let from_index = match status {
    Task::Enqueued { content } => content.uid,
    Task::Processing { content } => content.uid,
    Task::Failed { content } => content.task.uid,
    Task::Succeeded { content } => content.uid,
};

assert_eq!(task.get_task_uid(), from_index);
source

pub async fn get_tasks(&self) -> Result<TasksResults, Error>

Get the status of all tasks in a given index.

§Example
let tasks = index.get_tasks().await.unwrap();

assert!(tasks.results.len() > 0);
source

pub async fn get_tasks_with( &self, tasks_query: &TasksQuery<'_, TasksPaginationFilters> ) -> Result<TasksResults, Error>

Get the status of all tasks in a given index.

§Example
let mut query = TasksSearchQuery::new(&client);
query.with_index_uids(["none_existant"]);

let tasks = index.get_tasks_with(&query).await.unwrap();

assert!(tasks.results.len() > 0);
source

pub async fn get_stats(&self) -> Result<IndexStats, Error>

Get stats of an index.

§Example
let stats = index.get_stats().await.unwrap();

assert_eq!(stats.is_indexing, false);
source

pub async fn wait_for_task( &self, task_id: impl AsRef<u32>, interval: Option<Duration>, timeout: Option<Duration> ) -> Result<Task, Error>

Wait until Meilisearch processes a Task, and get its status.

interval = The frequency at which the server should be polled. Default = 50ms

timeout = The maximum time to wait for processing to complete. Default = 5000ms

If the waited time exceeds timeout then an Error::Timeout will be returned.

See also [Client::wait_for_task, Task::wait_for_completion].

§Example
let movies = client.index("movies_index_wait_for_task");

let task = movies.add_documents(&[
    Document { id: 0, kind: "title".into(), value: "The Social Network".to_string() },
    Document { id: 1, kind: "title".into(), value: "Harry Potter and the Sorcerer's Stone".to_string() },
], None).await.unwrap();

let status = movies.wait_for_task(task, None, None).await.unwrap();

assert!(matches!(status, Task::Succeeded { .. }));
source

pub async fn add_documents_in_batches<T: Serialize>( &self, documents: &[T], batch_size: Option<usize>, primary_key: Option<&str> ) -> Result<Vec<TaskInfo>, Error>

Add documents to the index in batches.

documents = A slice of documents

batch_size = Optional parameter that allows you to specify the size of the batch

batch_size is 1000 by default

§Example
#[derive(Serialize, Deserialize, Debug)]
struct Movie {
    name: String,
    description: String,
}

let movie_index = client.index("add_documents_in_batches");

let tasks = movie_index.add_documents_in_batches(&[
 Movie {
        name: String::from("Interstellar"),
        description: String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")
 },
 Movie {
        // note that the id field can only take alphanumerics characters (and '-' and '/')
        name: String::from("MrsDoubtfire"),
        description: String::from("Loving but irresponsible dad Daniel Hillard, estranged from his exasperated spouse, is crushed by a court order allowing only weekly visits with his kids. When Daniel learns his ex needs a housekeeper, he gets the job -- disguised as an English nanny. Soon he becomes not only his children's best pal but the kind of parent he should have been from the start.")
 },
 Movie {
        name: String::from("Apollo13"),
        description: String::from("The true story of technical troubles that scuttle the Apollo 13 lunar mission in 1971, risking the lives of astronaut Jim Lovell and his crew, with the failed journey turning into a thrilling saga of heroism. Drifting more than 200,000 miles from Earth, the astronauts work furiously with the ground crew to avert tragedy.")
    }],
    Some(1),
    Some("name")
).await.unwrap();

client.wait_for_task(tasks.last().unwrap(), None, None).await.unwrap();

let movies = movie_index.get_documents::<Movie>().await.unwrap();

assert!(movies.results.len() >= 3);
source

pub async fn update_documents_in_batches<T: Serialize>( &self, documents: &[T], batch_size: Option<usize>, primary_key: Option<&str> ) -> Result<Vec<TaskInfo>, Error>

Update documents to the index in batches.

documents = A slice of documents

batch_size = Optional parameter that allows you to specify the size of the batch

batch_size is 1000 by default

§Example
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
struct Movie {
    name: String,
    description: String,
}

let movie_index = client.index("update_documents_in_batches");

let tasks = movie_index.add_documents_in_batches(&[
 Movie {
        name: String::from("Interstellar"),
        description: String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")
 },
 Movie {
        // note that the id field can only take alphanumerics characters (and '-' and '/')
        name: String::from("MrsDoubtfire"),
        description: String::from("Loving but irresponsible dad Daniel Hillard, estranged from his exasperated spouse, is crushed by a court order allowing only weekly visits with his kids. When Daniel learns his ex needs a housekeeper, he gets the job -- disguised as an English nanny. Soon he becomes not only his children's best pal but the kind of parent he should have been from the start.")
 },
 Movie {
        name: String::from("Apollo13"),
        description: String::from("The true story of technical troubles that scuttle the Apollo 13 lunar mission in 1971, risking the lives of astronaut Jim Lovell and his crew, with the failed journey turning into a thrilling saga of heroism. Drifting more than 200,000 miles from Earth, the astronauts work furiously with the ground crew to avert tragedy.")
    }],
    Some(1),
    Some("name")
).await.unwrap();

client.wait_for_task(tasks.last().unwrap(), None, None).await.unwrap();

let movies = movie_index.get_documents::<Movie>().await.unwrap();
assert!(movies.results.len() >= 3);

let updated_movies = [
 Movie {
        name: String::from("Interstellar"),
        description: String::from("Updated!")
 },
 Movie {
        // note that the id field can only take alphanumerics characters (and '-' and '/')
        name: String::from("MrsDoubtfire"),
        description: String::from("Updated!")
 },
 Movie {
        name: String::from("Apollo13"),
        description: String::from("Updated!")
}];

let tasks = movie_index.update_documents_in_batches(&updated_movies, Some(1), None).await.unwrap();

client.wait_for_task(tasks.last().unwrap(), None, None).await.unwrap();

let movies_updated = movie_index.get_documents::<Movie>().await.unwrap();

assert!(movies_updated.results.len() >= 3);
source§

impl Index

source

pub async fn get_settings(&self) -> Result<Settings, Error>

Get Settings of the Index.

§Example
let index = client.index("get_settings");

let settings = index.get_settings().await.unwrap();
source

pub async fn get_synonyms(&self) -> Result<HashMap<String, Vec<String>>, Error>

Get synonyms of the Index.

§Example
let index = client.index("get_synonyms");

let synonyms = index.get_synonyms().await.unwrap();
source

pub async fn get_pagination(&self) -> Result<PaginationSetting, Error>

Get pagination of the Index.

§Example
let index = client.index("get_pagination");

let pagination = index.get_pagination().await.unwrap();
source

pub async fn get_stop_words(&self) -> Result<Vec<String>, Error>

Get stop-words of the Index.

§Example
let index = client.index("get_stop_words");

let stop_words = index.get_stop_words().await.unwrap();
source

pub async fn get_ranking_rules(&self) -> Result<Vec<String>, Error>

Get ranking rules of the Index.

§Example
let index = client.index("get_ranking_rules");

let ranking_rules = index.get_ranking_rules().await.unwrap();
source

pub async fn get_filterable_attributes(&self) -> Result<Vec<String>, Error>

Get filterable attributes of the Index.

§Example
let index = client.index("get_filterable_attributes");

let filterable_attributes = index.get_filterable_attributes().await.unwrap();
source

pub async fn get_sortable_attributes(&self) -> Result<Vec<String>, Error>

Get sortable attributes of the Index.

§Example
let index = client.index("get_sortable_attributes");

let sortable_attributes = index.get_sortable_attributes().await.unwrap();
source

pub async fn get_distinct_attribute(&self) -> Result<Option<String>, Error>

Get the distinct attribute of the Index.

§Example
let index = client.index("get_distinct_attribute");

let distinct_attribute = index.get_distinct_attribute().await.unwrap();
source

pub async fn get_searchable_attributes(&self) -> Result<Vec<String>, Error>

Get searchable attributes of the Index.

§Example
let index = client.index("get_searchable_attributes");

let searchable_attributes = index.get_searchable_attributes().await.unwrap();
source

pub async fn get_displayed_attributes(&self) -> Result<Vec<String>, Error>

Get displayed attributes of the Index.

§Example
let index = client.index("get_displayed_attributes");

let displayed_attributes = index.get_displayed_attributes().await.unwrap();
source

pub async fn get_faceting(&self) -> Result<FacetingSettings, Error>

Get faceting settings of the Index.

§Example
let index = client.index("get_faceting");

let faceting = index.get_faceting().await.unwrap();
source

pub async fn get_dictionary(&self) -> Result<Vec<String>, Error>

Get dictionary of the Index.

§Example
let index = client.index("get_dictionary");

let dictionary = index.get_dictionary().await.unwrap();
source

pub async fn get_proximity_precision(&self) -> Result<String, Error>

Get proximity_precision of the Index.

§Example
let index = client.index("get_proximity_precision");

let proximity_precision = index.get_proximity_precision().await.unwrap();
source

pub async fn get_typo_tolerance(&self) -> Result<TypoToleranceSettings, Error>

Get typo tolerance of the Index.

let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
let index = client.index("get_typo_tolerance");

let typo_tolerance = index.get_typo_tolerance().await.unwrap();
source

pub async fn set_settings(&self, settings: &Settings) -> Result<TaskInfo, Error>

Update settings of the Index.

Updates in the settings are partial. This means that any parameters corresponding to a None value will be left unchanged.

§Example
let mut index = client.index("set_settings");

let stop_words = vec![String::from("a"), String::from("the"), String::from("of")];
let settings = Settings::new()
    .with_stop_words(stop_words.clone())
    .with_pagination(PaginationSetting {max_total_hits: 100}
);

let task = index.set_settings(&settings).await.unwrap();
source

pub async fn set_synonyms( &self, synonyms: &HashMap<String, Vec<String>> ) -> Result<TaskInfo, Error>

Update synonyms of the Index.

§Example
let mut index = client.index("set_synonyms");

let mut synonyms = std::collections::HashMap::new();
synonyms.insert(String::from("wolverine"), vec![String::from("xmen"), String::from("logan")]);
synonyms.insert(String::from("logan"), vec![String::from("xmen"), String::from("wolverine")]);
synonyms.insert(String::from("wow"), vec![String::from("world of warcraft")]);

let task = index.set_synonyms(&synonyms).await.unwrap();
source

pub async fn set_pagination( &self, pagination: PaginationSetting ) -> Result<TaskInfo, Error>

Update pagination of the Index.

§Example
let mut index = client.index("set_pagination");

let pagination = PaginationSetting {max_total_hits:100};
let task = index.set_pagination(pagination).await.unwrap();
source

pub async fn set_stop_words( &self, stop_words: impl IntoIterator<Item = impl AsRef<str>> ) -> Result<TaskInfo, Error>

Update stop-words of the Index.

§Example
let mut index = client.index("set_stop_words");

let stop_words = ["the", "of", "to"];
let task = index.set_stop_words(&stop_words).await.unwrap();
source

pub async fn set_ranking_rules( &self, ranking_rules: impl IntoIterator<Item = impl AsRef<str>> ) -> Result<TaskInfo, Error>

Update ranking rules of the Index.

§Example
let mut index = client.index("set_ranking_rules");

let ranking_rules = [
    "words",
    "typo",
    "proximity",
    "attribute",
    "sort",
    "exactness",
    "release_date:asc",
    "rank:desc",
];
let task = index.set_ranking_rules(ranking_rules).await.unwrap();
source

pub async fn set_filterable_attributes( &self, filterable_attributes: impl IntoIterator<Item = impl AsRef<str>> ) -> Result<TaskInfo, Error>

Update filterable attributes of the Index.

§Example
let mut index = client.index("set_filterable_attributes");

let filterable_attributes = ["genre", "director"];
let task = index.set_filterable_attributes(&filterable_attributes).await.unwrap();
source

pub async fn set_sortable_attributes( &self, sortable_attributes: impl IntoIterator<Item = impl AsRef<str>> ) -> Result<TaskInfo, Error>

Update sortable attributes of the Index.

§Example
let mut index = client.index("set_sortable_attributes");

let sortable_attributes = ["genre", "director"];
let task = index.set_sortable_attributes(&sortable_attributes).await.unwrap();
source

pub async fn set_distinct_attribute( &self, distinct_attribute: impl AsRef<str> ) -> Result<TaskInfo, Error>

Update the distinct attribute of the Index.

§Example
let mut index = client.index("set_distinct_attribute");

let task = index.set_distinct_attribute("movie_id").await.unwrap();
source

pub async fn set_searchable_attributes( &self, searchable_attributes: impl IntoIterator<Item = impl AsRef<str>> ) -> Result<TaskInfo, Error>

Update searchable attributes of the Index.

§Example
let mut index = client.index("set_searchable_attributes");

let task = index.set_searchable_attributes(["title", "description", "uid"]).await.unwrap();
source

pub async fn set_displayed_attributes( &self, displayed_attributes: impl IntoIterator<Item = impl AsRef<str>> ) -> Result<TaskInfo, Error>

Update displayed attributes of the Index.

§Example
let mut index = client.index("set_displayed_attributes");

let task = index.set_displayed_attributes(["title", "description", "release_date", "rank", "poster"]).await.unwrap();
source

pub async fn set_faceting( &self, faceting: &FacetingSettings ) -> Result<TaskInfo, Error>

Update faceting settings of the Index.

§Example
let mut index = client.index("set_faceting");

let mut faceting = FacetingSettings {
    max_values_per_facet: 12,
};

let task = index.set_faceting(&faceting).await.unwrap();
source

pub async fn set_dictionary( &self, dictionary: impl IntoIterator<Item = impl AsRef<str>> ) -> Result<TaskInfo, Error>

Update dictionary of the Index.

§Example
let mut index = client.index("set_dictionary");

let task = index.set_dictionary(["J. K.", "J. R. R."]).await.unwrap();
source

pub async fn set_typo_tolerance( &self, typo_tolerance: &TypoToleranceSettings ) -> Result<TaskInfo, Error>

Update typo tolerance settings of the Index.

§Example
let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
let mut index = client.index("set_typo_tolerance");

let typo_tolerance = TypoToleranceSettings{
    enabled: Some(true),
    disable_on_attributes: Some(vec!["title".to_string()]),
    disable_on_words: Some(vec![]),
    min_word_size_for_typos: Some(MinWordSizeForTypos::default()),
};

let task = index.set_typo_tolerance(&typo_tolerance).await.unwrap();
source

pub async fn set_proximity_precision( &self, proximity_precision: String ) -> Result<TaskInfo, Error>

Update proximity-precision settings of the Index.

§Example
let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
let mut index = client.index("set_proximity_precision");

let task = index.set_proximity_precision("byWord".to_string()).await.unwrap();
source

pub async fn reset_settings(&self) -> Result<TaskInfo, Error>

Reset Settings of the Index.

All settings will be reset to their default value.

§Example
let mut index = client.index("reset_settings");

let task = index.reset_settings().await.unwrap();
source

pub async fn reset_synonyms(&self) -> Result<TaskInfo, Error>

Reset synonyms of the Index.

§Example
let mut index = client.index("reset_synonyms");

let task = index.reset_synonyms().await.unwrap();
source

pub async fn reset_pagination(&self) -> Result<TaskInfo, Error>

Reset pagination of the Index.

§Example
let mut index = client.index("reset_pagination");

let task = index.reset_pagination().await.unwrap();
source

pub async fn reset_stop_words(&self) -> Result<TaskInfo, Error>

Reset stop-words of the Index.

§Example
let mut index = client.index("reset_stop_words");

let task = index.reset_stop_words().await.unwrap();
source

pub async fn reset_ranking_rules(&self) -> Result<TaskInfo, Error>

Reset ranking rules of the Index to default value.

Default value: ["words", "typo", "proximity", "attribute", "sort", "exactness"].

§Example
let mut index = client.index("reset_ranking_rules");

let task = index.reset_ranking_rules().await.unwrap();
source

pub async fn reset_filterable_attributes(&self) -> Result<TaskInfo, Error>

Reset filterable attributes of the Index.

§Example
let mut index = client.index("reset_filterable_attributes");

let task = index.reset_filterable_attributes().await.unwrap();
source

pub async fn reset_sortable_attributes(&self) -> Result<TaskInfo, Error>

Reset sortable attributes of the Index.

§Example
let mut index = client.index("reset_sortable_attributes");

let task = index.reset_sortable_attributes().await.unwrap();
source

pub async fn reset_distinct_attribute(&self) -> Result<TaskInfo, Error>

Reset the distinct attribute of the Index.

§Example
let mut index = client.index("reset_distinct_attribute");

let task = index.reset_distinct_attribute().await.unwrap();
source

pub async fn reset_searchable_attributes(&self) -> Result<TaskInfo, Error>

Reset searchable attributes of the Index (enable all attributes).

§Example
let mut index = client.index("reset_searchable_attributes");

let task = index.reset_searchable_attributes().await.unwrap();
source

pub async fn reset_displayed_attributes(&self) -> Result<TaskInfo, Error>

Reset displayed attributes of the Index (enable all attributes).

§Example
let mut index = client.index("reset_displayed_attributes");

let task = index.reset_displayed_attributes().await.unwrap();
source

pub async fn reset_faceting(&self) -> Result<TaskInfo, Error>

Reset faceting settings of the Index.

§Example
let mut index = client.index("reset_faceting");

let task = index.reset_faceting().await.unwrap();
source

pub async fn reset_dictionary(&self) -> Result<TaskInfo, Error>

Reset dictionary of the Index.

§Example
let mut index = client.index("reset_dictionary");

let task = index.reset_dictionary().await.unwrap();
source

pub async fn reset_typo_tolerance(&self) -> Result<TaskInfo, Error>

Reset typo tolerance settings of the Index.

§Example
let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
let mut index = client.index("reset_typo_tolerance");

let task = index.reset_typo_tolerance().await.unwrap();
source

pub async fn reset_proximity_precision(&self) -> Result<TaskInfo, Error>

Reset proximity precision settings of the Index.

§Example
let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
let mut index = client.index("reset_proximity_precision");

let task = index.reset_proximity_precision().await.unwrap();

Trait Implementations§

source§

impl AsRef<str> for Index

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Index

source§

fn clone(&self) -> Index

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Index

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Serialize for Index

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Index

§

impl Send for Index

§

impl Sync for Index

§

impl Unpin for Index

§

impl UnwindSafe for Index

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more