private function preprocessAggregations(array $rawAggregation)
{
$processedAggregations = [];
foreach ($rawAggregation as $bucketName => $aggregation) {
while (isset($aggregation[$bucketName])) {
$aggregation = $aggregation[$bucketName];
}
if (isset($aggregation['buckets'])) {
foreach ($aggregation['buckets'] as $key => $currentBuket) {
if (isset($currentBuket['key'])) {
$key = $currentBuket['key'];
}
$processedAggregations[$bucketName][$key] = ['value' => $key, 'count' => $currentBuket['doc_count']];
}
}
if (isset($aggregation['sum_other_doc_count'])) {
$processedAggregations[$bucketName]['__other_docs'] = ['value' => '__other_docs', 'count' => $aggregation['sum_other_doc_count']];
}
}
return $processedAggregations;
}