From 61cfd8dc57c31992bee3318465224c8cdc5dea4c Mon Sep 17 00:00:00 2001 From: PSeitz Date: Mon, 13 Mar 2023 10:12:02 +0800 Subject: [PATCH] fix clippy (#1927) --- examples/aggregation.rs | 4 +- src/aggregation/agg_req.rs | 18 +- src/aggregation/agg_tests.rs | 259 +++++---- src/aggregation/bucket/histogram/histogram.rs | 326 ++++++----- src/aggregation/bucket/range.rs | 166 +++--- src/aggregation/bucket/term_agg.rs | 521 ++++++++++-------- src/aggregation/metric/stats.rs | 39 +- src/aggregation/mod.rs | 21 +- 8 files changed, 756 insertions(+), 598 deletions(-) diff --git a/examples/aggregation.rs b/examples/aggregation.rs index 61d4ba2f8..5ff62c717 100644 --- a/examples/aggregation.rs +++ b/examples/aggregation.rs @@ -204,7 +204,7 @@ fn main() -> tantivy::Result<()> { let agg_req: Aggregations = vec![( "group_by_stock".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation { field: "stock".to_string(), ranges: vec![ @@ -234,7 +234,7 @@ fn main() -> tantivy::Result<()> { )] .into_iter() .collect(), - }), + })), )] .into_iter() .collect(); diff --git a/src/aggregation/agg_req.rs b/src/aggregation/agg_req.rs index 45c6b2a61..0fe1d4f03 100644 --- a/src/aggregation/agg_req.rs +++ b/src/aggregation/agg_req.rs @@ -16,14 +16,14 @@ //! let agg_req1: Aggregations = vec![ //! ( //! "range".to_string(), -//! Aggregation::Bucket(BucketAggregation { +//! Aggregation::Bucket(Box::new(BucketAggregation { //! bucket_agg: BucketAggregationType::Range(RangeAggregation{ //! field: "score".to_string(), //! ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()], //! keyed: false, //! }), //! sub_aggregation: Default::default(), -//! }), +//! })), //! ), //! ] //! .into_iter() @@ -143,7 +143,7 @@ pub fn get_fast_field_names(aggs: &Aggregations) -> HashSet { #[serde(untagged)] pub enum Aggregation { /// Bucket aggregation, see [`BucketAggregation`] for details. - Bucket(BucketAggregation), + Bucket(Box), /// Metric aggregation, see [`MetricAggregation`] for details. Metric(MetricAggregation), } @@ -301,7 +301,7 @@ mod tests { fn serialize_to_json_test() { let agg_req1: Aggregations = vec![( "range".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation { field: "score".to_string(), ranges: vec![ @@ -313,7 +313,7 @@ mod tests { keyed: true, }), sub_aggregation: Default::default(), - }), + })), )] .into_iter() .collect(); @@ -351,7 +351,7 @@ mod tests { let agg_req2: Aggregations = vec![ ( "range".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation { field: "score2".to_string(), ranges: vec![ @@ -363,7 +363,7 @@ mod tests { ..Default::default() }), sub_aggregation: Default::default(), - }), + })), ), ( "metric".to_string(), @@ -377,7 +377,7 @@ mod tests { let agg_req1: Aggregations = vec![( "range".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation { field: "score".to_string(), ranges: vec![ @@ -389,7 +389,7 @@ mod tests { ..Default::default() }), sub_aggregation: agg_req2, - }), + })), )] .into_iter() .collect(); diff --git a/src/aggregation/agg_tests.rs b/src/aggregation/agg_tests.rs index 01e0fb4f2..b1642aab8 100644 --- a/src/aggregation/agg_tests.rs +++ b/src/aggregation/agg_tests.rs @@ -208,36 +208,36 @@ fn test_aggregation_level1() -> crate::Result<()> { ("average".to_string(), get_avg_req("score")), ( "range".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation { field: "score".to_string(), ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()], ..Default::default() }), sub_aggregation: Default::default(), - }), + })), ), ( "rangef64".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation { field: "score_f64".to_string(), ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()], ..Default::default() }), sub_aggregation: Default::default(), - }), + })), ), ( "rangei64".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation { field: "score_i64".to_string(), ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()], ..Default::default() }), sub_aggregation: Default::default(), - }), + })), ), ] .into_iter() @@ -308,13 +308,13 @@ fn test_aggregation_level2( ("average_in_range".to_string(), get_avg_req("score")), ( "term_agg".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Terms(TermsAggregation { field: "text".to_string(), ..Default::default() }), sub_aggregation: Default::default(), - }), + })), ), ] .into_iter() @@ -382,7 +382,7 @@ fn test_aggregation_level2( ("average".to_string(), get_avg_req("score")), ( "range".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation { field: "score".to_string(), ranges: vec![ @@ -393,11 +393,11 @@ fn test_aggregation_level2( ..Default::default() }), sub_aggregation: sub_agg_req.clone(), - }), + })), ), ( "rangef64".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation { field: "score_f64".to_string(), ranges: vec![ @@ -408,11 +408,11 @@ fn test_aggregation_level2( ..Default::default() }), sub_aggregation: sub_agg_req.clone(), - }), + })), ), ( "rangei64".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation { field: "score_i64".to_string(), ranges: vec![ @@ -423,7 +423,7 @@ fn test_aggregation_level2( ..Default::default() }), sub_aggregation: sub_agg_req, - }), + })), ), ] .into_iter() @@ -824,13 +824,16 @@ mod bench { b.iter(|| { let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "text_few_terms".to_string(), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "text_few_terms".to_string(), + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -860,13 +863,16 @@ mod bench { let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "text_many_terms".to_string(), - ..Default::default() - }), - sub_aggregation: sub_agg_req, - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "text_many_terms".to_string(), + ..Default::default() + }), + sub_aggregation: sub_agg_req, + } + .into(), + ), )] .into_iter() .collect(); @@ -887,13 +893,16 @@ mod bench { b.iter(|| { let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "text_many_terms".to_string(), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "text_many_terms".to_string(), + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -914,17 +923,20 @@ mod bench { b.iter(|| { let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "text_many_terms".to_string(), - order: Some(CustomOrder { - order: Order::Desc, - target: OrderTarget::Key, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "text_many_terms".to_string(), + order: Some(CustomOrder { + order: Order::Desc, + target: OrderTarget::Key, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -945,21 +957,24 @@ mod bench { b.iter(|| { let agg_req_1: Aggregations = vec![( "rangef64".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Range(RangeAggregation { - field: "score_f64".to_string(), - ranges: vec![ - (3f64..7000f64).into(), - (7000f64..20000f64).into(), - (20000f64..30000f64).into(), - (30000f64..40000f64).into(), - (40000f64..50000f64).into(), - (50000f64..60000f64).into(), - ], - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Range(RangeAggregation { + field: "score_f64".to_string(), + ranges: vec![ + (3f64..7000f64).into(), + (7000f64..20000f64).into(), + (20000f64..30000f64).into(), + (30000f64..40000f64).into(), + (40000f64..50000f64).into(), + (50000f64..60000f64).into(), + ], + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -989,21 +1004,24 @@ mod bench { let agg_req_1: Aggregations = vec![( "rangef64".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Range(RangeAggregation { - field: "score_f64".to_string(), - ranges: vec![ - (3f64..7000f64).into(), - (7000f64..20000f64).into(), - (20000f64..30000f64).into(), - (30000f64..40000f64).into(), - (40000f64..50000f64).into(), - (50000f64..60000f64).into(), - ], - ..Default::default() - }), - sub_aggregation: sub_agg_req, - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Range(RangeAggregation { + field: "score_f64".to_string(), + ranges: vec![ + (3f64..7000f64).into(), + (7000f64..20000f64).into(), + (20000f64..30000f64).into(), + (30000f64..40000f64).into(), + (40000f64..50000f64).into(), + (50000f64..60000f64).into(), + ], + ..Default::default() + }), + sub_aggregation: sub_agg_req, + } + .into(), + ), )] .into_iter() .collect(); @@ -1029,24 +1047,26 @@ mod bench { b.iter(|| { let agg_req_1: Aggregations = vec![( "rangef64".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 100f64, - hard_bounds: Some(HistogramBounds { - min: 1000.0, - max: 300_000.0, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 100f64, + hard_bounds: Some(HistogramBounds { + min: 1000.0, + max: 300_000.0, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); let collector = AggregationCollector::from_aggs(agg_req_1, None); - let searcher = reader.searcher(); searcher.search(&AllQuery, &collector).unwrap() }); @@ -1070,14 +1090,17 @@ mod bench { let agg_req_1: Aggregations = vec![( "rangef64".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 100f64, // 1000 buckets - ..Default::default() - }), - sub_aggregation: sub_agg_req, - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 100f64, // 1000 buckets + ..Default::default() + }), + sub_aggregation: sub_agg_req, + } + .into(), + ), )] .into_iter() .collect(); @@ -1098,14 +1121,17 @@ mod bench { b.iter(|| { let agg_req_1: Aggregations = vec![( "rangef64".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 100f64, // 1000 buckets - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 100f64, // 1000 buckets + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1148,18 +1174,21 @@ mod bench { ), ( "rangef64".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Range(RangeAggregation { - field: "score_f64".to_string(), - ranges: vec![ - (3f64..7000f64).into(), - (7000f64..20000f64).into(), - (20000f64..60000f64).into(), - ], - ..Default::default() - }), - sub_aggregation: sub_agg_req_1, - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Range(RangeAggregation { + field: "score_f64".to_string(), + ranges: vec![ + (3f64..7000f64).into(), + (7000f64..20000f64).into(), + (20000f64..60000f64).into(), + ], + ..Default::default() + }), + sub_aggregation: sub_agg_req_1, + } + .into(), + ), ), ] .into_iter() diff --git a/src/aggregation/bucket/histogram/histogram.rs b/src/aggregation/bucket/histogram/histogram.rs index 849a27e36..297a094cc 100644 --- a/src/aggregation/bucket/histogram/histogram.rs +++ b/src/aggregation/bucket/histogram/histogram.rs @@ -525,7 +525,7 @@ mod tests { let agg_req: Aggregations = vec![( "my_interval".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { field: "score_f64".to_string(), interval: 3.5, @@ -533,7 +533,7 @@ mod tests { ..Default::default() }), sub_aggregation: Default::default(), - }), + })), )] .into_iter() .collect(); @@ -551,7 +551,7 @@ mod tests { // With offset let agg_req: Aggregations = vec![( "my_interval".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { field: "score_f64".to_string(), interval: 3.5, @@ -559,7 +559,7 @@ mod tests { ..Default::default() }), sub_aggregation: Default::default(), - }), + })), )] .into_iter() .collect(); @@ -600,14 +600,14 @@ mod tests { let agg_req: Aggregations = vec![( "my_interval".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { field: "score_f64".to_string(), interval: 1.0, ..Default::default() }), sub_aggregation: Default::default(), - }), + })), )] .into_iter() .collect(); @@ -635,14 +635,14 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { field: "score_f64".to_string(), interval: 1.0, ..Default::default() }), sub_aggregation: Default::default(), - }), + })), )] .into_iter() .collect(); @@ -668,14 +668,14 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { field: "score_f64".to_string(), interval: 1.0, ..Default::default() }), sub_aggregation: Default::default(), - }), + })), )] .into_iter() .collect(); @@ -708,7 +708,7 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { field: "score_f64".to_string(), interval: 1.0, @@ -716,7 +716,7 @@ mod tests { ..Default::default() }), sub_aggregation: Default::default(), - }), + })), )] .into_iter() .collect(); @@ -746,7 +746,7 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { field: "score_f64".to_string(), interval: 1.0, @@ -757,7 +757,7 @@ mod tests { ..Default::default() }), sub_aggregation: Default::default(), - }), + })), )] .into_iter() .collect(); @@ -778,7 +778,7 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { field: "score_f64".to_string(), interval: 1.0, @@ -786,7 +786,7 @@ mod tests { ..Default::default() }), sub_aggregation: Default::default(), - }), + })), )] .into_iter() .collect(); @@ -809,7 +809,7 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { + Aggregation::Bucket(Box::new(BucketAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { field: "score_f64".to_string(), interval: 1.0, @@ -818,7 +818,7 @@ mod tests { ..Default::default() }), sub_aggregation: Default::default(), - }), + })), )] .into_iter() .collect(); @@ -853,18 +853,21 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 1.0, - hard_bounds: Some(HistogramBounds { - min: 2.0, - max: 12.0, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 1.0, + hard_bounds: Some(HistogramBounds { + min: 2.0, + max: 12.0, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -884,22 +887,25 @@ mod tests { // let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 1.0, - hard_bounds: Some(HistogramBounds { - min: 2.0, - max: 12.0, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 1.0, + hard_bounds: Some(HistogramBounds { + min: 2.0, + max: 12.0, + }), + extended_bounds: Some(HistogramBounds { + min: 2.0, + max: 12.0, + }), + ..Default::default() }), - extended_bounds: Some(HistogramBounds { - min: 2.0, - max: 12.0, - }), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -918,22 +924,25 @@ mod tests { // Invalid request let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 1.0, - hard_bounds: Some(HistogramBounds { - min: 2.0, - max: 12.0, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 1.0, + hard_bounds: Some(HistogramBounds { + min: 2.0, + max: 12.0, + }), + extended_bounds: Some(HistogramBounds { + min: 1.0, + max: 12.0, + }), + ..Default::default() }), - extended_bounds: Some(HistogramBounds { - min: 1.0, - max: 12.0, - }), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -963,14 +972,17 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 1.0, - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 1.0, + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1011,18 +1023,21 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 1.0, - extended_bounds: Some(HistogramBounds { - min: 2.0, - max: 12.0, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 1.0, + extended_bounds: Some(HistogramBounds { + min: 2.0, + max: 12.0, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1039,19 +1054,22 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 1.0, - extended_bounds: Some(HistogramBounds { min: 2.0, max: 5.0 }), - hard_bounds: Some(HistogramBounds { - min: 2.0, - max: 12.0, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 1.0, + extended_bounds: Some(HistogramBounds { min: 2.0, max: 5.0 }), + hard_bounds: Some(HistogramBounds { + min: 2.0, + max: 12.0, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1068,18 +1086,21 @@ mod tests { // hard_bounds will not extend the result let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 1.0, - hard_bounds: Some(HistogramBounds { - min: 2.0, - max: 12.0, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 1.0, + hard_bounds: Some(HistogramBounds { + min: 2.0, + max: 12.0, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1114,18 +1135,21 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 1.0, - extended_bounds: Some(HistogramBounds { - min: 2.0, - max: 12.0, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 1.0, + extended_bounds: Some(HistogramBounds { + min: 2.0, + max: 12.0, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: agg_req, - }), + sub_aggregation: agg_req, + } + .into(), + ), )] .into_iter() .collect(); @@ -1175,14 +1199,17 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 100000.0, - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 100000.0, + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1213,14 +1240,17 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "date".to_string(), - interval: 86400000000.0, // one day in microseconds - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "date".to_string(), + interval: 86400000000.0, // one day in microseconds + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1261,14 +1291,17 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 0.0, - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 0.0, + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1286,15 +1319,18 @@ mod tests { let agg_req: Aggregations = vec![( "histogram".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { - field: "score_f64".to_string(), - interval: 50.0, - keyed: true, - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { + field: "score_f64".to_string(), + interval: 50.0, + keyed: true, + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); diff --git a/src/aggregation/bucket/range.rs b/src/aggregation/bucket/range.rs index 674e3f22b..458900f85 100644 --- a/src/aggregation/bucket/range.rs +++ b/src/aggregation/bucket/range.rs @@ -475,14 +475,17 @@ mod tests { let agg_req: Aggregations = vec![( "range".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Range(RangeAggregation { - field: "fraction_f64".to_string(), - ranges: vec![(0f64..0.1f64).into(), (0.1f64..0.2f64).into()], - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Range(RangeAggregation { + field: "fraction_f64".to_string(), + ranges: vec![(0f64..0.1f64).into(), (0.1f64..0.2f64).into()], + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -516,14 +519,17 @@ mod tests { let agg_req: Aggregations = vec![( "range".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Range(RangeAggregation { - field: "fraction_f64".to_string(), - ranges: vec![(0f64..0.1f64).into(), (0.1f64..0.2f64).into()], - ..Default::default() - }), - sub_aggregation: sub_agg_req, - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Range(RangeAggregation { + field: "fraction_f64".to_string(), + ranges: vec![(0f64..0.1f64).into(), (0.1f64..0.2f64).into()], + ..Default::default() + }), + sub_aggregation: sub_agg_req, + } + .into(), + ), )] .into_iter() .collect(); @@ -548,14 +554,17 @@ mod tests { let agg_req: Aggregations = vec![( "range".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Range(RangeAggregation { - field: "fraction_f64".to_string(), - ranges: vec![(0f64..0.1f64).into(), (0.1f64..0.2f64).into()], - keyed: true, - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Range(RangeAggregation { + field: "fraction_f64".to_string(), + ranges: vec![(0f64..0.1f64).into(), (0.1f64..0.2f64).into()], + keyed: true, + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -585,25 +594,28 @@ mod tests { let agg_req: Aggregations = vec![( "range".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Range(RangeAggregation { - field: "fraction_f64".to_string(), - ranges: vec![ - RangeAggregationRange { - key: Some("custom-key-0-to-0.1".to_string()), - from: Some(0f64), - to: Some(0.1f64), - }, - RangeAggregationRange { - key: None, - from: Some(0.1f64), - to: Some(0.2f64), - }, - ], - keyed: false, - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Range(RangeAggregation { + field: "fraction_f64".to_string(), + ranges: vec![ + RangeAggregationRange { + key: Some("custom-key-0-to-0.1".to_string()), + from: Some(0f64), + to: Some(0.1f64), + }, + RangeAggregationRange { + key: None, + from: Some(0.1f64), + to: Some(0.2f64), + }, + ], + keyed: false, + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -642,25 +654,28 @@ mod tests { let agg_req: Aggregations = vec![( "date_ranges".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Range(RangeAggregation { - field: "date".to_string(), - ranges: vec![ - RangeAggregationRange { - key: None, - from: None, - to: Some(1546300800000000.0f64), - }, - RangeAggregationRange { - key: None, - from: Some(1546300800000000.0f64), - to: Some(1546387200000000.0f64), - }, - ], - keyed: false, - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Range(RangeAggregation { + field: "date".to_string(), + ranges: vec![ + RangeAggregationRange { + key: None, + from: None, + to: Some(1546300800000000.0f64), + }, + RangeAggregationRange { + key: None, + from: Some(1546300800000000.0f64), + to: Some(1546387200000000.0f64), + }, + ], + keyed: false, + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -704,18 +719,21 @@ mod tests { let agg_req: Aggregations = vec![( "range".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Range(RangeAggregation { - field: "fraction_f64".to_string(), - ranges: vec![RangeAggregationRange { - key: Some("custom-key-0-to-0.1".to_string()), - from: Some(0f64), - to: Some(0.1f64), - }], - keyed: true, - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Range(RangeAggregation { + field: "fraction_f64".to_string(), + ranges: vec![RangeAggregationRange { + key: Some("custom-key-0-to-0.1".to_string()), + from: Some(0f64), + to: Some(0.1f64), + }], + keyed: true, + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); diff --git a/src/aggregation/bucket/term_agg.rs b/src/aggregation/bucket/term_agg.rs index 098c981e9..9fd1d5093 100644 --- a/src/aggregation/bucket/term_agg.rs +++ b/src/aggregation/bucket/term_agg.rs @@ -559,13 +559,16 @@ mod tests { let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -581,15 +584,18 @@ mod tests { let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - size: Some(2), - split_size: Some(2), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + size: Some(2), + split_size: Some(2), + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -608,15 +614,18 @@ mod tests { // test min_doc_count let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - size: Some(2), - min_doc_count: Some(3), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + size: Some(2), + min_doc_count: Some(3), + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -676,17 +685,20 @@ mod tests { // sub agg desc let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - order: Some(CustomOrder { - order: Order::Asc, - target: OrderTarget::Count, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + order: Some(CustomOrder { + order: Order::Asc, + target: OrderTarget::Count, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: sub_agg.clone(), - }), + sub_aggregation: sub_agg.clone(), + } + .into(), + ), )] .into_iter() .collect(); @@ -711,45 +723,54 @@ mod tests { let agg_req: Aggregations = vec![ ( "my_scores1".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "score".to_string(), - order: Some(CustomOrder { - order: Order::Asc, - target: OrderTarget::Count, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "score".to_string(), + order: Some(CustomOrder { + order: Order::Asc, + target: OrderTarget::Count, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: sub_agg.clone(), - }), + sub_aggregation: sub_agg.clone(), + } + .into(), + ), ), ( "my_scores2".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "score_f64".to_string(), - order: Some(CustomOrder { - order: Order::Asc, - target: OrderTarget::Count, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "score_f64".to_string(), + order: Some(CustomOrder { + order: Order::Asc, + target: OrderTarget::Count, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: sub_agg.clone(), - }), + sub_aggregation: sub_agg.clone(), + } + .into(), + ), ), ( "my_scores3".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "score_i64".to_string(), - order: Some(CustomOrder { - order: Order::Asc, - target: OrderTarget::Count, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "score_i64".to_string(), + order: Some(CustomOrder { + order: Order::Asc, + target: OrderTarget::Count, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: sub_agg, - }), + sub_aggregation: sub_agg, + } + .into(), + ), ), ] .into_iter() @@ -850,17 +871,20 @@ mod tests { // sub agg desc let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - order: Some(CustomOrder { - order: Order::Desc, - target: OrderTarget::SubAggregation("avg_score".to_string()), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + order: Some(CustomOrder { + order: Order::Desc, + target: OrderTarget::SubAggregation("avg_score".to_string()), + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: sub_agg.clone(), - }), + sub_aggregation: sub_agg.clone(), + } + .into(), + ), )] .into_iter() .collect(); @@ -883,17 +907,20 @@ mod tests { // sub agg asc let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - order: Some(CustomOrder { - order: Order::Asc, - target: OrderTarget::SubAggregation("avg_score".to_string()), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + order: Some(CustomOrder { + order: Order::Asc, + target: OrderTarget::SubAggregation("avg_score".to_string()), + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: sub_agg.clone(), - }), + sub_aggregation: sub_agg.clone(), + } + .into(), + ), )] .into_iter() .collect(); @@ -917,17 +944,20 @@ mod tests { // sub agg multi value asc let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - order: Some(CustomOrder { - order: Order::Asc, - target: OrderTarget::SubAggregation("stats_score.avg".to_string()), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + order: Some(CustomOrder { + order: Order::Asc, + target: OrderTarget::SubAggregation("stats_score.avg".to_string()), + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: sub_agg.clone(), - }), + sub_aggregation: sub_agg.clone(), + } + .into(), + ), )] .into_iter() .collect(); @@ -951,17 +981,20 @@ mod tests { // sub agg invalid request let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - order: Some(CustomOrder { - order: Order::Asc, - target: OrderTarget::SubAggregation("doesnotexist".to_string()), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + order: Some(CustomOrder { + order: Order::Asc, + target: OrderTarget::SubAggregation("doesnotexist".to_string()), + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: sub_agg, - }), + sub_aggregation: sub_agg, + } + .into(), + ), )] .into_iter() .collect(); @@ -998,17 +1031,20 @@ mod tests { // key asc let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - order: Some(CustomOrder { - order: Order::Asc, - target: OrderTarget::Key, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + order: Some(CustomOrder { + order: Order::Asc, + target: OrderTarget::Key, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1025,18 +1061,21 @@ mod tests { // key desc and size cut_off let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - order: Some(CustomOrder { - order: Order::Asc, - target: OrderTarget::Key, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + order: Some(CustomOrder { + order: Order::Asc, + target: OrderTarget::Key, + }), + size: Some(2), + ..Default::default() }), - size: Some(2), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1056,19 +1095,22 @@ mod tests { // key asc and segment_size cut_off let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - order: Some(CustomOrder { - order: Order::Asc, - target: OrderTarget::Key, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + order: Some(CustomOrder { + order: Order::Asc, + target: OrderTarget::Key, + }), + size: Some(2), + segment_size: Some(2), + ..Default::default() }), - size: Some(2), - segment_size: Some(2), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1086,17 +1128,20 @@ mod tests { // key desc let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - order: Some(CustomOrder { - order: Order::Desc, - target: OrderTarget::Key, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + order: Some(CustomOrder { + order: Order::Desc, + target: OrderTarget::Key, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1113,18 +1158,21 @@ mod tests { // key desc, size cut_off let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - order: Some(CustomOrder { - order: Order::Desc, - target: OrderTarget::Key, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + order: Some(CustomOrder { + order: Order::Desc, + target: OrderTarget::Key, + }), + size: Some(2), + ..Default::default() }), - size: Some(2), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1143,19 +1191,22 @@ mod tests { // key desc, segment_size cut_off let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - order: Some(CustomOrder { - order: Order::Desc, - target: OrderTarget::Key, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + order: Some(CustomOrder { + order: Order::Desc, + target: OrderTarget::Key, + }), + size: Some(2), + segment_size: Some(2), + ..Default::default() }), - size: Some(2), - segment_size: Some(2), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1184,14 +1235,17 @@ mod tests { let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - min_doc_count: Some(0), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + min_doc_count: Some(0), + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1224,15 +1278,18 @@ mod tests { let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - size: Some(2), - segment_size: Some(2), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + size: Some(2), + segment_size: Some(2), + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1254,16 +1311,19 @@ mod tests { let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - size: Some(2), - segment_size: Some(2), - show_term_doc_count_error: Some(false), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + size: Some(2), + segment_size: Some(2), + show_term_doc_count_error: Some(false), + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1316,14 +1376,17 @@ mod tests { let agg_req: Aggregations = vec![( "my_texts".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "text_id".to_string(), - min_doc_count: Some(0), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "text_id".to_string(), + min_doc_count: Some(0), + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1344,19 +1407,22 @@ mod tests { fn test_json_format() -> crate::Result<()> { let agg_req: Aggregations = vec![( "term_agg_test".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - size: Some(2), - segment_size: Some(2), - order: Some(CustomOrder { - target: OrderTarget::Key, - order: Order::Desc, + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + size: Some(2), + segment_size: Some(2), + order: Some(CustomOrder { + target: OrderTarget::Key, + order: Order::Desc, + }), + ..Default::default() }), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); @@ -1391,14 +1457,17 @@ mod tests { // test alias shard_size, split_size let agg_req: Aggregations = vec![( "term_agg_test".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "string_id".to_string(), - split_size: Some(2), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "string_id".to_string(), + split_size: Some(2), + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect(); diff --git a/src/aggregation/metric/stats.rs b/src/aggregation/metric/stats.rs index 495c17212..b335c1d53 100644 --- a/src/aggregation/metric/stats.rs +++ b/src/aggregation/metric/stats.rs @@ -380,24 +380,27 @@ mod tests { ), ( "range".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Range(RangeAggregation { - field: "score".to_string(), - ranges: vec![ - (3f64..7f64).into(), - (7f64..19f64).into(), - (19f64..20f64).into(), - ], - ..Default::default() - }), - sub_aggregation: iter::once(( - "stats".to_string(), - Aggregation::Metric(MetricAggregation::Stats( - StatsAggregation::from_field_name("score".to_string()), - )), - )) - .collect(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Range(RangeAggregation { + field: "score".to_string(), + ranges: vec![ + (3f64..7f64).into(), + (7f64..19f64).into(), + (19f64..20f64).into(), + ], + ..Default::default() + }), + sub_aggregation: iter::once(( + "stats".to_string(), + Aggregation::Metric(MetricAggregation::Stats( + StatsAggregation::from_field_name("score".to_string()), + )), + )) + .collect(), + } + .into(), + ), ), ] .into_iter() diff --git a/src/aggregation/mod.rs b/src/aggregation/mod.rs index a995dbffa..676a56333 100644 --- a/src/aggregation/mod.rs +++ b/src/aggregation/mod.rs @@ -130,14 +130,14 @@ //! let agg_req_1: Aggregations = vec![ //! ( //! "range".to_string(), -//! Aggregation::Bucket(BucketAggregation { +//! Aggregation::Bucket(Box::new(BucketAggregation { //! bucket_agg: BucketAggregationType::Range(RangeAggregation{ //! field: "score".to_string(), //! ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()], //! keyed: false, //! }), //! sub_aggregation: sub_agg_req_1.clone(), -//! }), +//! })), //! ), //! ] //! .into_iter() @@ -614,13 +614,16 @@ mod tests { let searcher = reader.searcher(); let agg: Aggregations = vec![( "jsonagg".to_string(), - Aggregation::Bucket(BucketAggregation { - bucket_agg: BucketAggregationType::Terms(TermsAggregation { - field: "json.color".to_string(), - ..Default::default() - }), - sub_aggregation: Default::default(), - }), + Aggregation::Bucket( + BucketAggregation { + bucket_agg: BucketAggregationType::Terms(TermsAggregation { + field: "json.color".to_string(), + ..Default::default() + }), + sub_aggregation: Default::default(), + } + .into(), + ), )] .into_iter() .collect();