File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ create_an_index_1: |-
1111 client.create_index('movies', {'primaryKey': 'id'})
1212update_an_index_1 : |-
1313 client.index('movies').update(primary_key='id')
14+ compact_index_1 : |-
15+ client.index('movies').compact()
1416delete_an_index_1 : |-
1517 client.delete_index('movies')
1618 // OR
Original file line number Diff line number Diff line change @@ -2333,3 +2333,17 @@ def _build_url(
23332333 if primary_key is None and csv_delimiter is None :
23342334 return f"{ self .config .paths .index } /{ self .uid } /{ self .config .paths .document } "
23352335 return f"{ self .config .paths .index } /{ self .uid } /{ self .config .paths .document } ?{ parse .urlencode (parameters )} "
2336+
2337+ def compact (self ) -> TaskInfo :
2338+ """
2339+ Trigger the compaction of the index.
2340+ This is an asynchronous operation in Meilisearch.
2341+
2342+ Returns
2343+ -------
2344+ task_info: TaskInfo
2345+ Contains information to track the progress of the compaction task.
2346+ """
2347+ path = f"{ self .config .paths .index } /{ self .uid } /compact"
2348+ task = self .http .post (path )
2349+ return TaskInfo (** task )
Original file line number Diff line number Diff line change @@ -219,3 +219,18 @@ def test_delete_index(client):
219219 client .wait_for_task (deleted .task_uid )
220220 with pytest .raises (MeilisearchApiError ):
221221 client .get_index (uid = common .INDEX_UID )
222+
223+
224+ @pytest .mark .usefixtures ("indexes_sample" )
225+ def test_index_compact (client ):
226+ """Tests the compaction of an index."""
227+ index = client .index (common .INDEX_UID )
228+ # Get stats before compaction
229+ stats_before = index .get_stats ()
230+
231+ task_info = index .compact ()
232+ client .wait_for_task (task_info .task_uid )
233+ stats_after = index .get_stats ()
234+
235+ assert stats_before .number_of_documents == stats_after .number_of_documents
236+ assert stats_after .is_indexing is False
You can’t perform that action at this time.
0 commit comments