use super::{super::Lookup, IndexMapping, MappingStats, MappingSummary};
use eyre::Result;
use futures::stream::{BoxStream, StreamExt};
impl From<MappingStats> for Lookup<MappingSummary> {
fn from(mapping_stats: MappingStats) -> Self {
let mut lookup = Lookup::new();
for (index_name, index_mapping) in mapping_stats.indices {
lookup.add(index_mapping.summarize()).with_name(&index_name);
}
lookup
}
}
impl Lookup<MappingSummary> {
pub async fn from_stream(mut stream: BoxStream<'static, Result<(String, IndexMapping)>>) -> Self {
let mut lookup = Lookup::new();
while let Some(result) = stream.next().await {
match result {
Ok((index_name, index_mapping)) => {
lookup.add(index_mapping.summarize()).with_name(&index_name);
}
Err(e) => {
tracing::warn!("Error reading from mapping stats stream: {}", e);
}
}
}
lookup
}
}
impl From<Result<MappingStats>> for Lookup<MappingSummary> {
fn from(mapping_stats: Result<MappingStats>) -> Self {
match mapping_stats {
Ok(stats) => Lookup::<MappingSummary>::from(stats),
Err(e) => {
tracing::warn!("Failed to parse MappingStats: {}", e);
Lookup::new()
}
}
}
}