From bd0818405e3897ce0befce2351db203b05f59d03 Mon Sep 17 00:00:00 2001 From: jedarden Date: Sat, 9 May 2026 11:19:40 -0400 Subject: [PATCH] Phase 1 (miroir-cdo): Fix index stats response parsing Fix response body parsing in get_index_stats to properly parse JSON response from scatter nodes. Previously was trying to access JSON fields directly on Vec bytes. Co-Authored-By: Claude Opus 4.7 Bead-Id: miroir-cdo --- crates/miroir-proxy/src/routes/indexes.rs | 25 +++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/crates/miroir-proxy/src/routes/indexes.rs b/crates/miroir-proxy/src/routes/indexes.rs index fd4913e..d861bc4 100644 --- a/crates/miroir-proxy/src/routes/indexes.rs +++ b/crates/miroir-proxy/src/routes/indexes.rs @@ -291,19 +291,22 @@ async fn get_index_stats( { if let Some(resp) = result.responses.first() { if resp.status == 200 { - // Extract stats - if let Some(docs) = resp.body.get("numberOfDocuments").and_then(|v| v.as_u64()) - { - // Use max document count across replicas (more accurate) - total_documents = total_documents.max(docs); - } + // Parse response body as JSON + if let Ok(json) = serde_json::from_slice::(&resp.body) { + // Extract stats + if let Some(docs) = json.get("numberOfDocuments").and_then(|v| v.as_u64()) + { + // Use max document count across replicas (more accurate) + total_documents = total_documents.max(docs); + } - if let Some(indexing) = resp.body.get("isIndexing").and_then(|v| v.as_bool()) { - is_indexing = is_indexing || indexing; - } + if let Some(indexing) = json.get("isIndexing").and_then(|v| v.as_bool()) { + is_indexing = is_indexing || indexing; + } - if let Some(fields) = resp.body.get("fieldDistribution") { - field_distributions.push(fields.clone()); + if let Some(fields) = json.get("fieldDistribution") { + field_distributions.push(fields.clone()); + } } } }