Skip to content

Instantly share code, notes, and snippets.

@jakebathman
Created May 4, 2022 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakebathman/393542ce25b25fa44201b95d924d2a41 to your computer and use it in GitHub Desktop.
Save jakebathman/393542ce25b25fa44201b95d924d2a41 to your computer and use it in GitHub Desktop.
Quick summary of Meilisearch batch indexing progress
<?php
$tasks = json_decode(file_get_contents('http://127.0.0.1:7700/indexes/standards/tasks'), true);
$durations = [];
$batches = [];
$batchDocs = [];
foreach ($tasks['results'] as $task) {
$uid = $task['uid'];
$duration = duration($task['duration']) ?? 0;
if (isset($task['details']['receivedDocuments'])) {
// Batches are separate
if (isset($task['batchUid'])) {
$batchId = $task['batchUid'];
if (! isset($batchDocs[$batchId])) {
$batchDocs[$batchId] = 0;
}
$batchDocs[$batchId] += $task['details']['receivedDocuments'];
$indexed = $task['details']['indexedDocuments'];
$batches[$batchId] = [
'status' => $task['status'],
'duration' => $duration,
'receivedDocuments' => number_format($batchDocs[$batchId]),
'indexedDocuments' => $indexed !== null
? number_format($indexed)
: null,
'documentsPerSecond' => $indexed > 0
? number_format($indexed / $duration)
: null,
];
} else {
$durations[$uid] = $uid . ',' . $duration;
}
}
}
ksort($batches, SORT_NUMERIC);
ksort($durations, SORT_NUMERIC);
if (! empty($batches)) {
echo json_encode($batches, JSON_PRETTY_PRINT);
exit();
}
echo json_encode($durations, JSON_PRETTY_PRINT);
function duration($d)
{
if (is_null($d)) {
return 0;
}
return str_ireplace('s', '', str_ireplace('PT', '', $d));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment