@@ -559,6 +559,73 @@ impl Index {
559559        . await 
560560    } 
561561
562+     /// Add a raw and unchecked payload to meilisearch. 
563+ /// This can be useful if your application is only forwarding data from other sources. 
564+ /// 
565+ /// If you send an already existing document (same id) the **whole existing document** will be overwritten by the new document. 
566+ /// Fields previously in the document not present in the new document are removed. 
567+ /// 
568+ /// For a partial update of the document see [Index::add_or_update_unchecked_payload]. 
569+ /// 
570+ /// # Example 
571+ /// 
572+ /// ``` 
573+ /// use serde::{Serialize, Deserialize}; 
574+ /// 
575+ /// # use meilisearch_sdk::{client::*, indexes::*}; 
576+ /// # use std::thread::sleep; 
577+ /// # use std::time::Duration; 
578+ /// # 
579+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); 
580+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); 
581+ /// # futures::executor::block_on(async move { 
582+ /// let client = Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY); 
583+ /// let movie_index = client.index("add_or_replace_unchecked_payload"); 
584+ /// 
585+ /// let task = movie_index.add_or_replace_unchecked_payload( 
586+ ///     r#"{ "id": 1, "body": "doggo" } 
587+ ///     { "id": 2, "body": "catto" }"#.as_bytes(), 
588+ ///     "application/x-ndjson", 
589+ ///     Some("id"), 
590+ ///   ).await.unwrap(); 
591+ /// // Meilisearch may take some time to execute the request so we are going to wait till it's completed 
592+ /// client.wait_for_task(task, None, None).await.unwrap(); 
593+ /// 
594+ /// let movies = movie_index.get_documents::<serde_json::Value>().await.unwrap(); 
595+ /// assert!(movies.results.len() == 2); 
596+ /// # movie_index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); 
597+ /// # }); 
598+ /// ``` 
599+ #[ cfg( not( target_arch = "wasm32" ) ) ]  
600+     pub  async  fn  add_or_replace_unchecked_payload < 
601+         T :  futures_io:: AsyncRead  + Send  + Sync  + ' static , 
602+     > ( 
603+         & self , 
604+         payload :  T , 
605+         content_type :  & str , 
606+         primary_key :  Option < & str > , 
607+     )  -> Result < TaskInfo ,  Error >  { 
608+         let  url = if  let  Some ( primary_key)  = primary_key { 
609+             format ! ( 
610+                 "{}/indexes/{}/documents?primaryKey={}" , 
611+                 self . client. host,  self . uid,  primary_key
612+             ) 
613+         }  else  { 
614+             format ! ( "{}/indexes/{}/documents" ,  self . client. host,  self . uid) 
615+         } ; 
616+         stream_request :: < ( ) ,  T ,  TaskInfo > ( 
617+             & url, 
618+             & self . client . api_key , 
619+             Method :: Post  { 
620+                 query :  ( ) , 
621+                 body :  payload, 
622+             } , 
623+             content_type, 
624+             202 , 
625+         ) 
626+         . await 
627+     } 
628+ 
562629    /// Alias for [Index::add_or_replace]. 
563630pub  async  fn  add_documents < T :  Serialize > ( 
564631        & self , 
@@ -648,6 +715,73 @@ impl Index {
648715        . await 
649716    } 
650717
718+     /// Add a raw and unchecked payload to meilisearch. 
719+ /// This can be useful if your application is only forwarding data from other sources. 
720+ /// 
721+ /// 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. 
722+ /// Thus, any fields not present in the new document are kept and remained unchanged. 
723+ /// 
724+ /// To completely overwrite a document, check out the [Index::add_or_replace_unchecked_payload] documents method. 
725+ /// 
726+ /// # Example 
727+ /// 
728+ /// ``` 
729+ /// use serde::{Serialize, Deserialize}; 
730+ /// 
731+ /// # use meilisearch_sdk::{client::*, indexes::*}; 
732+ /// # use std::thread::sleep; 
733+ /// # use std::time::Duration; 
734+ /// # 
735+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); 
736+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); 
737+ /// # futures::executor::block_on(async move { 
738+ /// let client = Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY); 
739+ /// let movie_index = client.index("add_or_replace_unchecked_payload"); 
740+ /// 
741+ /// let task = movie_index.add_or_update_unchecked_payload( 
742+ ///     r#"{ "id": 1, "body": "doggo" } 
743+ ///     { "id": 2, "body": "catto" }"#.as_bytes(), 
744+ ///     "application/x-ndjson", 
745+ ///     Some("id"), 
746+ ///   ).await.unwrap(); 
747+ /// // Meilisearch may take some time to execute the request so we are going to wait till it's completed 
748+ /// client.wait_for_task(task, None, None).await.unwrap(); 
749+ /// 
750+ /// let movies = movie_index.get_documents::<serde_json::Value>().await.unwrap(); 
751+ /// assert!(movies.results.len() == 2); 
752+ /// # movie_index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap(); 
753+ /// # }); 
754+ /// ``` 
755+ #[ cfg( not( target_arch = "wasm32" ) ) ]  
756+     pub  async  fn  add_or_update_unchecked_payload < 
757+         T :  futures_io:: AsyncRead  + Send  + Sync  + ' static , 
758+     > ( 
759+         & self , 
760+         payload :  T , 
761+         content_type :  & str , 
762+         primary_key :  Option < & str > , 
763+     )  -> Result < TaskInfo ,  Error >  { 
764+         let  url = if  let  Some ( primary_key)  = primary_key { 
765+             format ! ( 
766+                 "{}/indexes/{}/documents?primaryKey={}" , 
767+                 self . client. host,  self . uid,  primary_key
768+             ) 
769+         }  else  { 
770+             format ! ( "{}/indexes/{}/documents" ,  self . client. host,  self . uid) 
771+         } ; 
772+         stream_request :: < ( ) ,  T ,  TaskInfo > ( 
773+             & url, 
774+             & self . client . api_key , 
775+             Method :: Put  { 
776+                 query :  ( ) , 
777+                 body :  payload, 
778+             } , 
779+             content_type, 
780+             202 , 
781+         ) 
782+         . await 
783+     } 
784+ 
651785    /// Delete all documents in the index. 
652786/// 
653787/// # Example 
0 commit comments