|
| 1 | +--- |
| 2 | +title: Batches — Meilisearch API reference |
| 3 | +description: The /batches route allows you to monitor how Meilisearch is grouping and processing asynchronous operations. |
| 4 | +--- |
| 5 | + |
| 6 | +# Batches |
| 7 | + |
| 8 | +The `/batches` route gives information about the progress of batches of [asynchronous operations](/learn/async/asynchronous_operations). |
| 9 | + |
| 10 | +## Batch object |
| 11 | + |
| 12 | +```json |
| 13 | +{ |
| 14 | + "uid": 0, |
| 15 | + "details": { |
| 16 | + "receivedDocuments": 6, |
| 17 | + "indexedDocuments": 6 |
| 18 | + }, |
| 19 | + "stats": { |
| 20 | + "totalNbTasks": 1, |
| 21 | + "status": { |
| 22 | + "succeeded": 1 |
| 23 | + }, |
| 24 | + "types": { |
| 25 | + "documentAdditionOrUpdate": 1 |
| 26 | + }, |
| 27 | + "indexUids": { |
| 28 | + "INDEX_NAME": 1 |
| 29 | + } |
| 30 | + }, |
| 31 | + "duration": "PT0.250518S", |
| 32 | + "startedAt": "2024-12-10T15:20:30.18182Z", |
| 33 | + "finishedAt": "2024-12-10T15:20:30.432338Z", |
| 34 | + "progress": { |
| 35 | + "steps": [ |
| 36 | + { |
| 37 | + "currentStep": "extracting words", |
| 38 | + "finished": 2, |
| 39 | + "total": 9, |
| 40 | + }, |
| 41 | + { |
| 42 | + "currentStep": "document", |
| 43 | + "finished": 30546, |
| 44 | + "total": 31944, |
| 45 | + } |
| 46 | + ], |
| 47 | + "percentage": 32.8471 |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +### `uid` |
| 53 | + |
| 54 | +**Type**: Integer<br /> |
| 55 | +**Description**: Unique sequential identifier of the batch. Starts at `0` and increases by one for every new patch. |
| 56 | + |
| 57 | +### `details` |
| 58 | + |
| 59 | +**Type**: Object<br /> |
| 60 | +**Description**: Basic information on the types tasks in a batch. Consult the [task object reference](/reference/api/tasks#details) for an exhaustive list of possible values. |
| 61 | + |
| 62 | +### `progress` |
| 63 | + |
| 64 | +**Type**: Object<br /> |
| 65 | +**Description**: Object containing two fields: `steps` and `percentage`. Once Meilisearch has fully processed a batch, its `progress` is set to `null`. |
| 66 | + |
| 67 | +#### `steps` |
| 68 | + |
| 69 | +Information about the current operations Meilisearch is performing in this batch. A step may consist of multiple substeps. |
| 70 | + |
| 71 | +| Name | Description | |
| 72 | +| :-----------------| :------------------------------------------------- | |
| 73 | +| **`currentStep`** | A string describing the operation | |
| 74 | +| **`total`** | The total number of operations in the step | |
| 75 | +| **`finished`** | The number of operations Meilisearch has completed | |
| 76 | + |
| 77 | +<Capsule intent="tip" title=""> |
| 78 | +If Meilisearch is taking longer than expected to process a batch, monitor the `steps` array. If the `finished` field of the last item in the `steps` array does not update, Meilisearch may be stuck. |
| 79 | +</Capsule> |
| 80 | + |
| 81 | +#### `percentage` |
| 82 | + |
| 83 | +The percentage of completed operations, calculated from all current steps and substeps. This value is a rough estimate and may not always reflect the current state of the batch due to how different steps are processed more quickly than others. |
| 84 | + |
| 85 | +### `stats` |
| 86 | + |
| 87 | +**Type**: Object<br /> |
| 88 | +**Description**: Detailed information on the payload of all tasks in a batch. |
| 89 | + |
| 90 | +#### `totalNbTasks` |
| 91 | + |
| 92 | +Number of tasks in the batch. |
| 93 | + |
| 94 | +#### `status` |
| 95 | + |
| 96 | +Object listing the [status of each task](/reference/api/tasks#status) in the batch. Contains five keys whose values correspond to the number of tasks with that status. |
| 97 | + |
| 98 | +#### `types` |
| 99 | + |
| 100 | +List with the `types` of tasks contained in the batch. |
| 101 | + |
| 102 | +#### `indexUids` |
| 103 | + |
| 104 | +List of the number of tasks in the batch separated by the indexes they affect. |
| 105 | + |
| 106 | +### `duration` |
| 107 | + |
| 108 | +**Type**: String<br /> |
| 109 | +**Description**: The total elapsed time the batch spent in the `processing` state, in [ISO 8601](https://www.ionos.com/digitalguide/websites/web-development/iso-8601/) format. Set to `null` while the batch is processing tasks |
| 110 | + |
| 111 | +### `startedAt` |
| 112 | + |
| 113 | +**Type**: String<br /> |
| 114 | +**Description**: The date and time when the batch began `processing`, in [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format |
| 115 | + |
| 116 | +### `finishedAt` |
| 117 | + |
| 118 | +**Type**: String<br /> |
| 119 | +**Description**: The date and time when the tasks finished `processing`, whether `failed`, `succeeded`, or `canceled`, in [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format |
| 120 | + |
| 121 | +## Get batches |
| 122 | + |
| 123 | +<RouteHighlighter method="GET" route="/batches"/> |
| 124 | + |
| 125 | +List all batches, regardless of index. The batch objects are contained in the `results` array. |
| 126 | + |
| 127 | +Batches are always returned in descending order of `uid`. This means that by default, **the most recently created batch objects appear first**. |
| 128 | + |
| 129 | +Batch results are [paginated](/learn/async/paginating_tasks) and can be [filtered](/learn/async/filtering_tasks) with query parameters. |
| 130 | + |
| 131 | +<Capsule intent="danger" title="`/batches` parameters and tasks"> |
| 132 | +Some query parameters for `/batches`, such as `uids` and `statuses`, target tasks instead of batches. |
| 133 | + |
| 134 | +For example, `?uids=0` returns a batch containing the task with a `taskUid` equal to `0`, instead of a batch with a `batchUid` equal to `0`. |
| 135 | +</Capsule> |
| 136 | + |
| 137 | +### Query parameters |
| 138 | + |
| 139 | +| Query Parameter | Default Value | Description | |
| 140 | +| ---------------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------- | |
| 141 | +| **`uids`** | `*` (all task uids) | Select batches containing the tasks with the specified `uid`s. Separate multiple task `uids` with a comma (`,`) | |
| 142 | +| **`batchUids`** | `*` (all batch uids) | Filter batches by their `uid`. Separate multiple batch `uids` with a comma (`,`) | |
| 143 | +| **`indexUids`** | `*` (all indexes) | Select batches containing tasks affecting the specified indexes. Separate multiple `indexUids` with a comma (`,`) | |
| 144 | +| **`statuses`** | `*` (all statuses) | Select batches containing tasks with the specified `status`. Separate multiple task `statuses` with a comma (`,`) | |
| 145 | +| **`types`** | `*` (all types) | Select batches containing tasks with the specified `type`. Separate multiple task `types` with a comma (`,`) | |
| 146 | +| **`limit`** | `20` | Number of batches to return | |
| 147 | +| **`from`** | `uid` of the last created batch | `uid` of the first batch returned | |
| 148 | +| **`reverse`** | `false` | If `true`, returns results in the reverse order, from oldest to most recent | |
| 149 | +| **`beforeEnqueuedAt`** | `*` (all tasks) | Select batches containing tasks with the specified `enqueuedAt` field | |
| 150 | +| **`beforeStartedAt`** | `*` (all tasks) | Select batches containing tasks with the specified `startedAt` field | |
| 151 | +| **`beforeFinishedAt`** | `*` (all tasks) | Select batches containing tasks with the specified `finishedAt` field | |
| 152 | +| **`afterEnqueuedAt`** | `*` (all tasks) | Select batches containing tasks with the specified `enqueuedAt` field | |
| 153 | +| **`afterStartedAt`** | `*` (all tasks) | Select batches containing tasks with the specified `startedAt` field | |
| 154 | +| **`afterFinishedAt`** | `*` (all tasks) | Select batches containing tasks with the specified `finishedAt` field | |
| 155 | + |
| 156 | +### Response |
| 157 | + |
| 158 | +| Name | Type | Description | |
| 159 | +| :------------ | :------ | :----------------------------------------------------------------------------------------------------------------------------- | |
| 160 | +| **`results`** | Array | An array of [batch objects](#batch-object) | |
| 161 | +| **`total`** | Integer | Total number of batches matching the filter or query | |
| 162 | +| **`limit`** | Integer | Number of batches returned | |
| 163 | +| **`from`** | Integer | `uid` of the first batch returned | |
| 164 | +| **`next`** | Integer | Value passed to `from` to view the next "page" of results. When the value of `next` is `null`, there are no more tasks to view | |
| 165 | + |
| 166 | +### Example |
| 167 | + |
| 168 | +<CodeSamples id="get_all_batches_1" /> |
| 169 | + |
| 170 | +#### Response: `200 Ok` |
| 171 | + |
| 172 | +```json |
| 173 | +{ |
| 174 | + "results": [ |
| 175 | + { |
| 176 | + "uid": 2, |
| 177 | + "details": { |
| 178 | + "stopWords": [ |
| 179 | + "of", |
| 180 | + "the" |
| 181 | + ] |
| 182 | + }, |
| 183 | + "progress": null, |
| 184 | + "stats": { |
| 185 | + "totalNbTasks": 1, |
| 186 | + "status": { |
| 187 | + "succeeded": 1 |
| 188 | + }, |
| 189 | + "types": { |
| 190 | + "settingsUpdate": 1 |
| 191 | + }, |
| 192 | + "indexUids": { |
| 193 | + "INDEX_NAME": 1 |
| 194 | + } |
| 195 | + }, |
| 196 | + "duration": "PT0.110083S", |
| 197 | + "startedAt": "2024-12-10T15:49:04.995321Z", |
| 198 | + "finishedAt": "2024-12-10T15:49:05.105404Z" |
| 199 | + } |
| 200 | + ], |
| 201 | + "total": 3, |
| 202 | + "limit": 1, |
| 203 | + "from": 2, |
| 204 | + "next": 1 |
| 205 | +} |
| 206 | +``` |
| 207 | + |
| 208 | +## Get one batch |
| 209 | + |
| 210 | +<RouteHighlighter method="GET" route="/batches/{batch_uid}"/> |
| 211 | + |
| 212 | +Get a single batch. |
| 213 | + |
| 214 | +### Path parameters |
| 215 | + |
| 216 | +| Name | Type | Description | |
| 217 | +| :---------------- | :----- | :----------------------------------- | |
| 218 | +| **`batch_uid`** * | String | [`uid`](#uid) of the requested batch | |
| 219 | + |
| 220 | +### Example |
| 221 | + |
| 222 | +<CodeSamples id="get_batch_1" /> |
| 223 | + |
| 224 | +#### Response: `200 Ok` |
| 225 | + |
| 226 | +```json |
| 227 | +{ |
| 228 | + "uid": 1, |
| 229 | + "details": { |
| 230 | + "receivedDocuments": 1, |
| 231 | + "indexedDocuments": 1 |
| 232 | + }, |
| 233 | + "progress": null, |
| 234 | + "stats": { |
| 235 | + "totalNbTasks": 1, |
| 236 | + "status": { |
| 237 | + "succeeded": 1 |
| 238 | + }, |
| 239 | + "types": { |
| 240 | + "documentAdditionOrUpdate": 1 |
| 241 | + }, |
| 242 | + "indexUids": { |
| 243 | + "INDEX_NAME": 1 |
| 244 | + } |
| 245 | + }, |
| 246 | + "duration": "PT0.364788S", |
| 247 | + "startedAt": "2024-12-10T15:48:49.672141Z", |
| 248 | + "finishedAt": "2024-12-10T15:48:50.036929Z" |
| 249 | +} |
| 250 | +``` |
0 commit comments