Skip to content

Commit 2aa6057

Browse files
committed
feat: Adding support for index renaming.
1 parent 814f5a9 commit 2aa6057

File tree

2 files changed

+63
-21
lines changed

2 files changed

+63
-21
lines changed

meilisearch/client.py

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -531,27 +531,6 @@ def create_snapshot(self) -> TaskInfo:
531531

532532
return TaskInfo(**task)
533533

534-
def swap_indexes(self, parameters: List[Mapping[str, List[str]]]) -> TaskInfo:
535-
"""Swap two indexes.
536-
537-
Parameters
538-
----------
539-
indexes:
540-
List of indexes to swap (ex: [{"indexes": ["indexA", "indexB"]}).
541-
542-
Returns
543-
-------
544-
task_info:
545-
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
546-
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
547-
548-
Raises
549-
------
550-
MeilisearchApiError
551-
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
552-
"""
553-
return TaskInfo(**self.http.post(self.config.paths.swap, parameters))
554-
555534
def get_tasks(self, parameters: Optional[MutableMapping[str, Any]] = None) -> TaskResults:
556535
"""Get all tasks.
557536
@@ -996,3 +975,50 @@ def _valid_uuid(uuid: str) -> bool:
996975
)
997976
match = uuid4hex.match(uuid)
998977
return bool(match)
978+
979+
def get_experimental_features(self) -> dict:
980+
"""Get current experimental features settings."""
981+
return self.http.get(self.config.paths.experimental_features)
982+
983+
def update_experimental_features(self, features: dict) -> dict:
984+
"""Update experimental features settings."""
985+
return self.http.patch(self.config.paths.experimental_features, body=features)
986+
987+
def enable_multimodal(self) -> dict:
988+
"""Enable multimodal experimental feature."""
989+
return self.update_experimental_features({"multimodal": True})
990+
991+
def disable_multimodal(self) -> dict:
992+
"""Disable multimodal experimental feature."""
993+
return self.update_experimental_features({"multimodal": False})
994+
995+
def swap_indexes(self, swaps: List[Dict[str, list]]) -> TaskInfo:
996+
"""
997+
Swap or rename indexes in Meilisearch.
998+
This method accepts a list of swap instructions.
999+
Each instruction must contain:
1000+
1001+
- "indexes": a list of exactly two index UIDs
1002+
- "rename" (optional): boolean flag
1003+
* False (default): swap two existing indexes
1004+
* True: rename index_a → index_b (index_b must NOT exist)
1005+
1006+
A single request can perform multiple swap or rename operations.
1007+
All operations in the request are atomic—either all succeed, or none do.
1008+
1009+
Example:
1010+
[
1011+
{"indexes": ["A", "B"]},
1012+
{"indexes": ["C_tmp", "C"], "rename": True}
1013+
]
1014+
1015+
Returns
1016+
-------
1017+
TaskInfo
1018+
Task information for the asynchronous swap/rename task.
1019+
"""
1020+
if not swaps or not all("indexes" in s and len(s["indexes"]) == 2 for s in swaps):
1021+
raise ValueError("Each swap must contain exactly two index UIDs under 'indexes' key.")
1022+
1023+
task = self.http.post("/swap-indexes",swaps)
1024+
return TaskInfo(**task)

meilisearch/index.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,3 +2347,19 @@ def compact(self) -> TaskInfo:
23472347
path = f"{self.config.paths.index}/{self.uid}/compact"
23482348
task = self.http.post(path)
23492349
return TaskInfo(**task)
2350+
2351+
def rename_index(self, new_name: str) -> TaskInfo:
2352+
"""
2353+
Rename the current Meilisearch index.
2354+
2355+
:param new_name: The new UID for the index.
2356+
:return: TaskInfo with information about the rename operation.
2357+
"""
2358+
payload = {"uid": new_name}
2359+
2360+
task = self.http.patch(
2361+
f"{self.config.paths.index}/{self.uid}",
2362+
payload,
2363+
)
2364+
2365+
return TaskInfo(**task)

0 commit comments

Comments
 (0)