@@ -202,6 +202,15 @@ pub struct DocumentsQuery<'a, Http: HttpClient> {
202202 /// Read the [dedicated guide](https://www.meilisearch.com/docs/learn/filtering_and_sorting) to learn the syntax.
203203 #[ serde( skip_serializing_if = "Option::is_none" ) ]
204204 pub filter : Option < & ' a str > ,
205+
206+ /// Retrieve documents by their IDs.
207+ ///
208+ /// When `ids` is provided, the SDK will call the `/documents/fetch` endpoint with a POST request.
209+ ///
210+ /// Note: IDs are represented as strings to keep consistency with [`Index::get_document`]. If your IDs
211+ /// are numeric, pass them as strings (e.g., `"1"`, `"2"`).
212+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
213+ pub ids : Option < Vec < & ' a str > > ,
205214}
206215
207216impl < ' a , Http : HttpClient > DocumentsQuery < ' a , Http > {
@@ -214,6 +223,7 @@ impl<'a, Http: HttpClient> DocumentsQuery<'a, Http> {
214223 fields : None ,
215224 sort : None ,
216225 filter : None ,
226+ ids : None ,
217227 }
218228 }
219229
@@ -314,6 +324,29 @@ impl<'a, Http: HttpClient> DocumentsQuery<'a, Http> {
314324 self
315325 }
316326
327+ /// Specify a list of document IDs to retrieve.
328+ ///
329+ /// # Example
330+ ///
331+ /// ```
332+ /// # use meilisearch_sdk::{client::*, indexes::*, documents::*};
333+ /// # use serde::{Deserialize, Serialize};
334+ /// #
335+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
336+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
337+ /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)).unwrap();
338+ /// let index = client.index("get_documents_by_ids_example");
339+ /// let mut query = DocumentsQuery::new(&index);
340+ /// query.with_ids(["1", "2"]);
341+ /// ```
342+ pub fn with_ids (
343+ & mut self ,
344+ ids : impl IntoIterator < Item = & ' a str > ,
345+ ) -> & mut DocumentsQuery < ' a , Http > {
346+ self . ids = Some ( ids. into_iter ( ) . collect ( ) ) ;
347+ self
348+ }
349+
317350 /// Execute the get documents query.
318351 ///
319352 /// # Example
@@ -468,6 +501,19 @@ mod tests {
468501 Ok ( ( ) )
469502 }
470503
504+ #[ meilisearch_test]
505+ async fn test_get_documents_by_ids ( client : Client , index : Index ) -> Result < ( ) , Error > {
506+ setup_test_index ( & client, & index) . await ?;
507+
508+ let documents = DocumentsQuery :: new ( & index)
509+ . with_ids ( [ "1" , "3" ] ) // retrieve by IDs
510+ . execute :: < MyObject > ( )
511+ . await ?;
512+
513+ assert_eq ! ( documents. results. len( ) , 2 ) ;
514+ Ok ( ( ) )
515+ }
516+
471517 #[ meilisearch_test]
472518 async fn test_delete_documents_with ( client : Client , index : Index ) -> Result < ( ) , Error > {
473519 setup_test_index ( & client, & index) . await ?;
0 commit comments