diff --git a/src/aggregation/agg_req.rs b/src/aggregation/agg_req.rs index 8b021b656..7b9c14af6 100644 --- a/src/aggregation/agg_req.rs +++ b/src/aggregation/agg_req.rs @@ -121,9 +121,14 @@ pub fn get_fast_field_names(aggs: &Aggregations) -> HashSet { /// This is a convenience function for upfront validation before executing aggregations. /// Returns an error if any field doesn't exist or is not a fast field. /// +/// Validation is intentionally opt-in rather than baked into aggregation execution: the +/// default lenient behavior (returning empty results for missing fields) supports +/// schema evolution and federated queries where the same request runs against segments +/// or indices with different schemas. +/// /// # Example /// ``` -/// use tantivy::aggregation::agg_req::{Aggregations, validate_aggregation_fields}; +/// use tantivy::aggregation::agg_req::{Aggregations, validate_aggregation_fields_exist}; /// use tantivy::schema::{Schema, FAST}; /// use tantivy::Index; /// @@ -144,12 +149,12 @@ pub fn get_fast_field_names(aggs: &Aggregations) -> HashSet { /// /// // Validate fields before executing /// for segment_reader in searcher.segment_readers() { -/// validate_aggregation_fields(&agg_req, segment_reader)?; +/// validate_aggregation_fields_exist(&agg_req, segment_reader)?; /// } /// # Ok(()) /// # } /// ``` -pub fn validate_aggregation_fields( +pub fn validate_aggregation_fields_exist( aggs: &Aggregations, reader: &crate::SegmentReader, ) -> crate::Result<()> { diff --git a/src/aggregation/agg_tests.rs b/src/aggregation/agg_tests.rs index 3042753cb..09d9752e9 100644 --- a/src/aggregation/agg_tests.rs +++ b/src/aggregation/agg_tests.rs @@ -1455,7 +1455,8 @@ fn test_aggregation_field_validation_helper() { ) .unwrap(); - let result = crate::aggregation::agg_req::validate_aggregation_fields(&agg_req, segment_reader); + let result = + crate::aggregation::agg_req::validate_aggregation_fields_exist(&agg_req, segment_reader); assert!(result.is_err()); match result { Err(crate::TantivyError::FieldNotFound(field_name)) => { @@ -1474,6 +1475,7 @@ fn test_aggregation_field_validation_helper() { ) .unwrap(); - let result = crate::aggregation::agg_req::validate_aggregation_fields(&agg_req, segment_reader); + let result = + crate::aggregation::agg_req::validate_aggregation_fields_exist(&agg_req, segment_reader); assert!(result.is_ok()); }