diff --git a/src/aggregation/agg_req.rs b/src/aggregation/agg_req.rs index 261386327..9dfe662d9 100644 --- a/src/aggregation/agg_req.rs +++ b/src/aggregation/agg_req.rs @@ -100,16 +100,16 @@ pub(crate) struct BucketAggregationInternal { } impl BucketAggregationInternal { - pub(crate) fn as_histogram(&self) -> &HistogramAggregation { + pub(crate) fn as_histogram(&self) -> Option<&HistogramAggregation> { match &self.bucket_agg { - BucketAggregationType::Histogram(histogram) => histogram, - _ => panic!("unexpected aggregation"), + BucketAggregationType::Histogram(histogram) => Some(histogram), + _ => None, } } - pub(crate) fn as_term(&self) -> &TermsAggregation { + pub(crate) fn as_term(&self) -> Option<&TermsAggregation> { match &self.bucket_agg { - BucketAggregationType::Terms(terms) => terms, - _ => panic!("unexpected aggregation"), + BucketAggregationType::Terms(terms) => Some(terms), + _ => None, } } } diff --git a/src/aggregation/agg_result.rs b/src/aggregation/agg_result.rs index 0cd5ec915..0c90abd43 100644 --- a/src/aggregation/agg_result.rs +++ b/src/aggregation/agg_result.rs @@ -179,15 +179,16 @@ impl BucketResult { IntermediateBucketResult::Histogram { buckets } => { let buckets = intermediate_buckets_to_final_buckets( buckets, - req.as_histogram(), + req.as_histogram().expect("unexpected aggregation"), &req.sub_aggregation, ); BucketResult::Histogram { buckets } } - IntermediateBucketResult::Terms(terms) => { - terms.into_final_result(req.as_term(), &req.sub_aggregation) - } + IntermediateBucketResult::Terms(terms) => terms.into_final_result( + req.as_term().expect("unexpected aggregation"), + &req.sub_aggregation, + ), } } } diff --git a/src/aggregation/bucket/term_agg.rs b/src/aggregation/bucket/term_agg.rs index fe9758132..b66a37838 100644 --- a/src/aggregation/bucket/term_agg.rs +++ b/src/aggregation/bucket/term_agg.rs @@ -51,6 +51,9 @@ use crate::DocId; /// /// # Limitations/Compatibility /// +/// Each segment returns up to [segment_size](TermsAggregation::segment_size) results. This +/// differences to elasticsearch behaviour. +/// /// # Request JSON Format /// ```json /// { @@ -87,6 +90,8 @@ pub struct TermsAggregation { /// include doc_count_error_upper_bound, which is an upper bound to the error on the /// doc_count returned by each shard. It’s the sum of the size of the largest bucket on /// each segment that didn’t fit into `shard_size`. + /// + /// Defaults to true. #[serde(default = "default_show_term_doc_count_error")] pub show_term_doc_count_error: bool,