@@ -276,7 +276,7 @@ impl<Http: HttpClient> Index<Http> {
276276 /// # });
277277 /// ```
278278 #[ must_use]
279- pub fn search ( & self ) -> SearchQuery < Http > {
279+ pub fn search ( & self ) -> SearchQuery < ' _ , Http > {
280280 SearchQuery :: new ( self )
281281 }
282282
@@ -1773,15 +1773,19 @@ pub struct IndexUpdater<'a, Http: HttpClient> {
17731773 pub client : & ' a Client < Http > ,
17741774 #[ serde( skip_serializing) ]
17751775 pub uid : String ,
1776+ /// New uid to rename the index to
1777+ #[ serde( rename = "uid" , skip_serializing_if = "Option::is_none" ) ]
1778+ pub new_uid : Option < String > ,
17761779 pub primary_key : Option < String > ,
17771780}
17781781
17791782impl < ' a , Http : HttpClient > IndexUpdater < ' a , Http > {
1780- pub fn new ( uid : impl AsRef < str > , client : & Client < Http > ) -> IndexUpdater < Http > {
1783+ pub fn new ( uid : impl AsRef < str > , client : & Client < Http > ) -> IndexUpdater < ' _ , Http > {
17811784 IndexUpdater {
17821785 client,
17831786 primary_key : None ,
17841787 uid : uid. as_ref ( ) . to_string ( ) ,
1788+ new_uid : None ,
17851789 }
17861790 }
17871791 /// Define the new `primary_key` to set on the [Index].
@@ -1829,6 +1833,12 @@ impl<'a, Http: HttpClient> IndexUpdater<'a, Http> {
18291833 self
18301834 }
18311835
1836+ /// Define a new `uid` to rename the index.
1837+ pub fn with_uid ( & mut self , new_uid : impl AsRef < str > ) -> & mut IndexUpdater < ' a , Http > {
1838+ self . new_uid = Some ( new_uid. as_ref ( ) . to_string ( ) ) ;
1839+ self
1840+ }
1841+
18321842 /// Execute the update of an [Index] using the [`IndexUpdater`].
18331843 ///
18341844 /// # Example
@@ -1976,7 +1986,7 @@ pub struct IndexesQuery<'a, Http: HttpClient> {
19761986
19771987impl < ' a , Http : HttpClient > IndexesQuery < ' a , Http > {
19781988 #[ must_use]
1979- pub fn new ( client : & Client < Http > ) -> IndexesQuery < Http > {
1989+ pub fn new ( client : & Client < Http > ) -> IndexesQuery < ' _ , Http > {
19801990 IndexesQuery {
19811991 client,
19821992 offset : None ,
@@ -2223,6 +2233,40 @@ mod tests {
22232233 Ok ( ( ) )
22242234 }
22252235
2236+ #[ meilisearch_test]
2237+ async fn test_rename_index_via_update ( client : Client , name : String ) -> Result < ( ) , Error > {
2238+ let from = format ! ( "{name}_from" ) ;
2239+ let to = format ! ( "{name}_to" ) ;
2240+
2241+ // Create source index
2242+ client
2243+ . create_index ( & from, None )
2244+ . await ?
2245+ . wait_for_completion ( & client, None , None )
2246+ . await ?;
2247+
2248+ // Rename using index update
2249+ IndexUpdater :: new ( & from, & client)
2250+ . with_uid ( & to)
2251+ . execute ( )
2252+ . await ?
2253+ . wait_for_completion ( & client, None , None )
2254+ . await ?;
2255+
2256+ // New index should exist
2257+ let new_index = client. get_index ( & to) . await ?;
2258+ assert_eq ! ( new_index. uid, to) ;
2259+
2260+ // cleanup
2261+ new_index
2262+ . delete ( )
2263+ . await ?
2264+ . wait_for_completion ( & client, None , None )
2265+ . await ?;
2266+
2267+ Ok ( ( ) )
2268+ }
2269+
22262270 #[ meilisearch_test]
22272271 async fn test_add_documents_ndjson ( client : Client , index : Index ) -> Result < ( ) , Error > {
22282272 let ndjson = r#"{ "id": 1, "body": "doggo" }{ "id": 2, "body": "catto" }"# . as_bytes ( ) ;
0 commit comments