Skip to content

Commit 64bf93b

Browse files
add compact route
1 parent 33ef2db commit 64bf93b

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

.code-samples.meilisearch.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,9 @@ rename_an_index_1: |-
15181518
-X PATCH 'MEILISEARCH_URL/indexes/INDEX_A' \
15191519
-H 'Content-Type: application/json' \
15201520
--data-binary '{ "uid": "INDEX_B" }'
1521-
1521+
compact_index_1: |-
1522+
curl \
1523+
-X POST 'MEILISEARCH_URL/indexes/INDEX_UID/compact'
15221524
15231525
### Code samples for experimental features
15241526
experimental_get_metrics_1: |-

reference/api/compact.mdx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Compact
3+
description: Use the `/compact` route to reduce database fragmentation.
4+
---
5+
6+
import { RouteHighlighter } from '/snippets/route_highlighter.mdx'
7+
8+
import CodeSamplesCompactIndex1 from '/snippets/samples/code_samples_compact_index_1.mdx';
9+
10+
Index fragmentation occurs naturally as you use Meilisearch and can lead to decreased performance over time. `/compact` reorganizes the database and prunes unused space, which may lead to improved indexing and search speeds.
11+
12+
<Tip>
13+
To obtain a rough estimate of your index's fragmentation, query the `/stats` route and compute the ratio between `databaseSize` and `usedDatabaseSize`. If the ratio is >= X.Y, compacting your indexes may improve performance.
14+
</Tip>
15+
16+
## Compact database
17+
18+
<RouteHighlighter method="POST" path="/indexes/{index_uid}/compact" />
19+
20+
Compact the specified index.
21+
22+
### Example
23+
24+
<CodeSamplesCompactIndex1 />
25+
26+
#### Response: `202 Accepted`
27+
28+
```json
29+
{
30+
"taskUid": 1,
31+
"indexUid": "INDEX_NAME",
32+
"status": "enqueued",
33+
"type": "IndexCompaction",
34+
"enqueuedAt": "2025-01-01T00:00:00.000000Z"
35+
}
36+
```

0 commit comments

Comments
 (0)