fix clippy (#1927)

This commit is contained in:
PSeitz
2023-03-13 10:12:02 +08:00
committed by GitHub
parent 064518156f
commit 61cfd8dc57
8 changed files with 756 additions and 598 deletions

View File

@@ -204,7 +204,7 @@ fn main() -> tantivy::Result<()> {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"group_by_stock".to_string(), "group_by_stock".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Range(RangeAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation {
field: "stock".to_string(), field: "stock".to_string(),
ranges: vec![ ranges: vec![
@@ -234,7 +234,7 @@ fn main() -> tantivy::Result<()> {
)] )]
.into_iter() .into_iter()
.collect(), .collect(),
}), })),
)] )]
.into_iter() .into_iter()
.collect(); .collect();

View File

@@ -16,14 +16,14 @@
//! let agg_req1: Aggregations = vec![ //! let agg_req1: Aggregations = vec![
//! ( //! (
//! "range".to_string(), //! "range".to_string(),
//! Aggregation::Bucket(BucketAggregation { //! Aggregation::Bucket(Box::new(BucketAggregation {
//! bucket_agg: BucketAggregationType::Range(RangeAggregation{ //! bucket_agg: BucketAggregationType::Range(RangeAggregation{
//! field: "score".to_string(), //! field: "score".to_string(),
//! ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()], //! ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()],
//! keyed: false, //! keyed: false,
//! }), //! }),
//! sub_aggregation: Default::default(), //! sub_aggregation: Default::default(),
//! }), //! })),
//! ), //! ),
//! ] //! ]
//! .into_iter() //! .into_iter()
@@ -143,7 +143,7 @@ pub fn get_fast_field_names(aggs: &Aggregations) -> HashSet<String> {
#[serde(untagged)] #[serde(untagged)]
pub enum Aggregation { pub enum Aggregation {
/// Bucket aggregation, see [`BucketAggregation`] for details. /// Bucket aggregation, see [`BucketAggregation`] for details.
Bucket(BucketAggregation), Bucket(Box<BucketAggregation>),
/// Metric aggregation, see [`MetricAggregation`] for details. /// Metric aggregation, see [`MetricAggregation`] for details.
Metric(MetricAggregation), Metric(MetricAggregation),
} }
@@ -301,7 +301,7 @@ mod tests {
fn serialize_to_json_test() { fn serialize_to_json_test() {
let agg_req1: Aggregations = vec![( let agg_req1: Aggregations = vec![(
"range".to_string(), "range".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Range(RangeAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation {
field: "score".to_string(), field: "score".to_string(),
ranges: vec![ ranges: vec![
@@ -313,7 +313,7 @@ mod tests {
keyed: true, keyed: true,
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -351,7 +351,7 @@ mod tests {
let agg_req2: Aggregations = vec![ let agg_req2: Aggregations = vec![
( (
"range".to_string(), "range".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Range(RangeAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation {
field: "score2".to_string(), field: "score2".to_string(),
ranges: vec![ ranges: vec![
@@ -363,7 +363,7 @@ mod tests {
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
), ),
( (
"metric".to_string(), "metric".to_string(),
@@ -377,7 +377,7 @@ mod tests {
let agg_req1: Aggregations = vec![( let agg_req1: Aggregations = vec![(
"range".to_string(), "range".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Range(RangeAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation {
field: "score".to_string(), field: "score".to_string(),
ranges: vec![ ranges: vec![
@@ -389,7 +389,7 @@ mod tests {
..Default::default() ..Default::default()
}), }),
sub_aggregation: agg_req2, sub_aggregation: agg_req2,
}), })),
)] )]
.into_iter() .into_iter()
.collect(); .collect();

View File

@@ -208,36 +208,36 @@ fn test_aggregation_level1() -> crate::Result<()> {
("average".to_string(), get_avg_req("score")), ("average".to_string(), get_avg_req("score")),
( (
"range".to_string(), "range".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Range(RangeAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation {
field: "score".to_string(), field: "score".to_string(),
ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()], ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()],
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
), ),
( (
"rangef64".to_string(), "rangef64".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Range(RangeAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation {
field: "score_f64".to_string(), field: "score_f64".to_string(),
ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()], ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()],
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
), ),
( (
"rangei64".to_string(), "rangei64".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Range(RangeAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation {
field: "score_i64".to_string(), field: "score_i64".to_string(),
ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()], ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()],
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
), ),
] ]
.into_iter() .into_iter()
@@ -308,13 +308,13 @@ fn test_aggregation_level2(
("average_in_range".to_string(), get_avg_req("score")), ("average_in_range".to_string(), get_avg_req("score")),
( (
"term_agg".to_string(), "term_agg".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Terms(TermsAggregation { bucket_agg: BucketAggregationType::Terms(TermsAggregation {
field: "text".to_string(), field: "text".to_string(),
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
), ),
] ]
.into_iter() .into_iter()
@@ -382,7 +382,7 @@ fn test_aggregation_level2(
("average".to_string(), get_avg_req("score")), ("average".to_string(), get_avg_req("score")),
( (
"range".to_string(), "range".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Range(RangeAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation {
field: "score".to_string(), field: "score".to_string(),
ranges: vec![ ranges: vec![
@@ -393,11 +393,11 @@ fn test_aggregation_level2(
..Default::default() ..Default::default()
}), }),
sub_aggregation: sub_agg_req.clone(), sub_aggregation: sub_agg_req.clone(),
}), })),
), ),
( (
"rangef64".to_string(), "rangef64".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Range(RangeAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation {
field: "score_f64".to_string(), field: "score_f64".to_string(),
ranges: vec![ ranges: vec![
@@ -408,11 +408,11 @@ fn test_aggregation_level2(
..Default::default() ..Default::default()
}), }),
sub_aggregation: sub_agg_req.clone(), sub_aggregation: sub_agg_req.clone(),
}), })),
), ),
( (
"rangei64".to_string(), "rangei64".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Range(RangeAggregation { bucket_agg: BucketAggregationType::Range(RangeAggregation {
field: "score_i64".to_string(), field: "score_i64".to_string(),
ranges: vec![ ranges: vec![
@@ -423,7 +423,7 @@ fn test_aggregation_level2(
..Default::default() ..Default::default()
}), }),
sub_aggregation: sub_agg_req, sub_aggregation: sub_agg_req,
}), })),
), ),
] ]
.into_iter() .into_iter()
@@ -824,13 +824,16 @@ mod bench {
b.iter(|| { b.iter(|| {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "text_few_terms".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
..Default::default() field: "text_few_terms".to_string(),
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -860,13 +863,16 @@ mod bench {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "text_many_terms".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
..Default::default() field: "text_many_terms".to_string(),
}), ..Default::default()
sub_aggregation: sub_agg_req, }),
}), sub_aggregation: sub_agg_req,
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -887,13 +893,16 @@ mod bench {
b.iter(|| { b.iter(|| {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "text_many_terms".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
..Default::default() field: "text_many_terms".to_string(),
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -914,17 +923,20 @@ mod bench {
b.iter(|| { b.iter(|| {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "text_many_terms".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "text_many_terms".to_string(),
order: Order::Desc, order: Some(CustomOrder {
target: OrderTarget::Key, order: Order::Desc,
target: OrderTarget::Key,
}),
..Default::default()
}), }),
..Default::default() sub_aggregation: Default::default(),
}), }
sub_aggregation: Default::default(), .into(),
}), ),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -945,21 +957,24 @@ mod bench {
b.iter(|| { b.iter(|| {
let agg_req_1: Aggregations = vec![( let agg_req_1: Aggregations = vec![(
"rangef64".to_string(), "rangef64".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Range(RangeAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Range(RangeAggregation {
ranges: vec![ field: "score_f64".to_string(),
(3f64..7000f64).into(), ranges: vec![
(7000f64..20000f64).into(), (3f64..7000f64).into(),
(20000f64..30000f64).into(), (7000f64..20000f64).into(),
(30000f64..40000f64).into(), (20000f64..30000f64).into(),
(40000f64..50000f64).into(), (30000f64..40000f64).into(),
(50000f64..60000f64).into(), (40000f64..50000f64).into(),
], (50000f64..60000f64).into(),
..Default::default() ],
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -989,21 +1004,24 @@ mod bench {
let agg_req_1: Aggregations = vec![( let agg_req_1: Aggregations = vec![(
"rangef64".to_string(), "rangef64".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Range(RangeAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Range(RangeAggregation {
ranges: vec![ field: "score_f64".to_string(),
(3f64..7000f64).into(), ranges: vec![
(7000f64..20000f64).into(), (3f64..7000f64).into(),
(20000f64..30000f64).into(), (7000f64..20000f64).into(),
(30000f64..40000f64).into(), (20000f64..30000f64).into(),
(40000f64..50000f64).into(), (30000f64..40000f64).into(),
(50000f64..60000f64).into(), (40000f64..50000f64).into(),
], (50000f64..60000f64).into(),
..Default::default() ],
}), ..Default::default()
sub_aggregation: sub_agg_req, }),
}), sub_aggregation: sub_agg_req,
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1029,24 +1047,26 @@ mod bench {
b.iter(|| { b.iter(|| {
let agg_req_1: Aggregations = vec![( let agg_req_1: Aggregations = vec![(
"rangef64".to_string(), "rangef64".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 100f64, field: "score_f64".to_string(),
hard_bounds: Some(HistogramBounds { interval: 100f64,
min: 1000.0, hard_bounds: Some(HistogramBounds {
max: 300_000.0, min: 1000.0,
max: 300_000.0,
}),
..Default::default()
}), }),
..Default::default() sub_aggregation: Default::default(),
}), }
sub_aggregation: Default::default(), .into(),
}), ),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
let collector = AggregationCollector::from_aggs(agg_req_1, None); let collector = AggregationCollector::from_aggs(agg_req_1, None);
let searcher = reader.searcher(); let searcher = reader.searcher();
searcher.search(&AllQuery, &collector).unwrap() searcher.search(&AllQuery, &collector).unwrap()
}); });
@@ -1070,14 +1090,17 @@ mod bench {
let agg_req_1: Aggregations = vec![( let agg_req_1: Aggregations = vec![(
"rangef64".to_string(), "rangef64".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 100f64, // 1000 buckets field: "score_f64".to_string(),
..Default::default() interval: 100f64, // 1000 buckets
}), ..Default::default()
sub_aggregation: sub_agg_req, }),
}), sub_aggregation: sub_agg_req,
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1098,14 +1121,17 @@ mod bench {
b.iter(|| { b.iter(|| {
let agg_req_1: Aggregations = vec![( let agg_req_1: Aggregations = vec![(
"rangef64".to_string(), "rangef64".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 100f64, // 1000 buckets field: "score_f64".to_string(),
..Default::default() interval: 100f64, // 1000 buckets
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1148,18 +1174,21 @@ mod bench {
), ),
( (
"rangef64".to_string(), "rangef64".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Range(RangeAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Range(RangeAggregation {
ranges: vec![ field: "score_f64".to_string(),
(3f64..7000f64).into(), ranges: vec![
(7000f64..20000f64).into(), (3f64..7000f64).into(),
(20000f64..60000f64).into(), (7000f64..20000f64).into(),
], (20000f64..60000f64).into(),
..Default::default() ],
}), ..Default::default()
sub_aggregation: sub_agg_req_1, }),
}), sub_aggregation: sub_agg_req_1,
}
.into(),
),
), ),
] ]
.into_iter() .into_iter()

View File

@@ -525,7 +525,7 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_interval".to_string(), "my_interval".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
field: "score_f64".to_string(), field: "score_f64".to_string(),
interval: 3.5, interval: 3.5,
@@ -533,7 +533,7 @@ mod tests {
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -551,7 +551,7 @@ mod tests {
// With offset // With offset
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_interval".to_string(), "my_interval".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
field: "score_f64".to_string(), field: "score_f64".to_string(),
interval: 3.5, interval: 3.5,
@@ -559,7 +559,7 @@ mod tests {
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -600,14 +600,14 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_interval".to_string(), "my_interval".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
field: "score_f64".to_string(), field: "score_f64".to_string(),
interval: 1.0, interval: 1.0,
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -635,14 +635,14 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
field: "score_f64".to_string(), field: "score_f64".to_string(),
interval: 1.0, interval: 1.0,
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -668,14 +668,14 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
field: "score_f64".to_string(), field: "score_f64".to_string(),
interval: 1.0, interval: 1.0,
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -708,7 +708,7 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
field: "score_f64".to_string(), field: "score_f64".to_string(),
interval: 1.0, interval: 1.0,
@@ -716,7 +716,7 @@ mod tests {
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -746,7 +746,7 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
field: "score_f64".to_string(), field: "score_f64".to_string(),
interval: 1.0, interval: 1.0,
@@ -757,7 +757,7 @@ mod tests {
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -778,7 +778,7 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
field: "score_f64".to_string(), field: "score_f64".to_string(),
interval: 1.0, interval: 1.0,
@@ -786,7 +786,7 @@ mod tests {
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -809,7 +809,7 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(Box::new(BucketAggregation {
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
field: "score_f64".to_string(), field: "score_f64".to_string(),
interval: 1.0, interval: 1.0,
@@ -818,7 +818,7 @@ mod tests {
..Default::default() ..Default::default()
}), }),
sub_aggregation: Default::default(), sub_aggregation: Default::default(),
}), })),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -853,18 +853,21 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 1.0, field: "score_f64".to_string(),
hard_bounds: Some(HistogramBounds { interval: 1.0,
min: 2.0, hard_bounds: Some(HistogramBounds {
max: 12.0, min: 2.0,
max: 12.0,
}),
..Default::default()
}), }),
..Default::default() sub_aggregation: Default::default(),
}), }
sub_aggregation: Default::default(), .into(),
}), ),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -884,22 +887,25 @@ mod tests {
// //
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 1.0, field: "score_f64".to_string(),
hard_bounds: Some(HistogramBounds { interval: 1.0,
min: 2.0, hard_bounds: Some(HistogramBounds {
max: 12.0, min: 2.0,
max: 12.0,
}),
extended_bounds: Some(HistogramBounds {
min: 2.0,
max: 12.0,
}),
..Default::default()
}), }),
extended_bounds: Some(HistogramBounds { sub_aggregation: Default::default(),
min: 2.0, }
max: 12.0, .into(),
}), ),
..Default::default()
}),
sub_aggregation: Default::default(),
}),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -918,22 +924,25 @@ mod tests {
// Invalid request // Invalid request
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 1.0, field: "score_f64".to_string(),
hard_bounds: Some(HistogramBounds { interval: 1.0,
min: 2.0, hard_bounds: Some(HistogramBounds {
max: 12.0, min: 2.0,
max: 12.0,
}),
extended_bounds: Some(HistogramBounds {
min: 1.0,
max: 12.0,
}),
..Default::default()
}), }),
extended_bounds: Some(HistogramBounds { sub_aggregation: Default::default(),
min: 1.0, }
max: 12.0, .into(),
}), ),
..Default::default()
}),
sub_aggregation: Default::default(),
}),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -963,14 +972,17 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 1.0, field: "score_f64".to_string(),
..Default::default() interval: 1.0,
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1011,18 +1023,21 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 1.0, field: "score_f64".to_string(),
extended_bounds: Some(HistogramBounds { interval: 1.0,
min: 2.0, extended_bounds: Some(HistogramBounds {
max: 12.0, min: 2.0,
max: 12.0,
}),
..Default::default()
}), }),
..Default::default() sub_aggregation: Default::default(),
}), }
sub_aggregation: Default::default(), .into(),
}), ),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1039,19 +1054,22 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 1.0, field: "score_f64".to_string(),
extended_bounds: Some(HistogramBounds { min: 2.0, max: 5.0 }), interval: 1.0,
hard_bounds: Some(HistogramBounds { extended_bounds: Some(HistogramBounds { min: 2.0, max: 5.0 }),
min: 2.0, hard_bounds: Some(HistogramBounds {
max: 12.0, min: 2.0,
max: 12.0,
}),
..Default::default()
}), }),
..Default::default() sub_aggregation: Default::default(),
}), }
sub_aggregation: Default::default(), .into(),
}), ),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1068,18 +1086,21 @@ mod tests {
// hard_bounds will not extend the result // hard_bounds will not extend the result
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 1.0, field: "score_f64".to_string(),
hard_bounds: Some(HistogramBounds { interval: 1.0,
min: 2.0, hard_bounds: Some(HistogramBounds {
max: 12.0, min: 2.0,
max: 12.0,
}),
..Default::default()
}), }),
..Default::default() sub_aggregation: Default::default(),
}), }
sub_aggregation: Default::default(), .into(),
}), ),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1114,18 +1135,21 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 1.0, field: "score_f64".to_string(),
extended_bounds: Some(HistogramBounds { interval: 1.0,
min: 2.0, extended_bounds: Some(HistogramBounds {
max: 12.0, min: 2.0,
max: 12.0,
}),
..Default::default()
}), }),
..Default::default() sub_aggregation: agg_req,
}), }
sub_aggregation: agg_req, .into(),
}), ),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1175,14 +1199,17 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 100000.0, field: "score_f64".to_string(),
..Default::default() interval: 100000.0,
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1213,14 +1240,17 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "date".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 86400000000.0, // one day in microseconds field: "date".to_string(),
..Default::default() interval: 86400000000.0, // one day in microseconds
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1261,14 +1291,17 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 0.0, field: "score_f64".to_string(),
..Default::default() interval: 0.0,
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1286,15 +1319,18 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"histogram".to_string(), "histogram".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Histogram(HistogramAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Histogram(HistogramAggregation {
interval: 50.0, field: "score_f64".to_string(),
keyed: true, interval: 50.0,
..Default::default() keyed: true,
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();

View File

@@ -475,14 +475,17 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"range".to_string(), "range".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Range(RangeAggregation { BucketAggregation {
field: "fraction_f64".to_string(), bucket_agg: BucketAggregationType::Range(RangeAggregation {
ranges: vec![(0f64..0.1f64).into(), (0.1f64..0.2f64).into()], field: "fraction_f64".to_string(),
..Default::default() ranges: vec![(0f64..0.1f64).into(), (0.1f64..0.2f64).into()],
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -516,14 +519,17 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"range".to_string(), "range".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Range(RangeAggregation { BucketAggregation {
field: "fraction_f64".to_string(), bucket_agg: BucketAggregationType::Range(RangeAggregation {
ranges: vec![(0f64..0.1f64).into(), (0.1f64..0.2f64).into()], field: "fraction_f64".to_string(),
..Default::default() ranges: vec![(0f64..0.1f64).into(), (0.1f64..0.2f64).into()],
}), ..Default::default()
sub_aggregation: sub_agg_req, }),
}), sub_aggregation: sub_agg_req,
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -548,14 +554,17 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"range".to_string(), "range".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Range(RangeAggregation { BucketAggregation {
field: "fraction_f64".to_string(), bucket_agg: BucketAggregationType::Range(RangeAggregation {
ranges: vec![(0f64..0.1f64).into(), (0.1f64..0.2f64).into()], field: "fraction_f64".to_string(),
keyed: true, ranges: vec![(0f64..0.1f64).into(), (0.1f64..0.2f64).into()],
}), keyed: true,
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -585,25 +594,28 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"range".to_string(), "range".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Range(RangeAggregation { BucketAggregation {
field: "fraction_f64".to_string(), bucket_agg: BucketAggregationType::Range(RangeAggregation {
ranges: vec![ field: "fraction_f64".to_string(),
RangeAggregationRange { ranges: vec![
key: Some("custom-key-0-to-0.1".to_string()), RangeAggregationRange {
from: Some(0f64), key: Some("custom-key-0-to-0.1".to_string()),
to: Some(0.1f64), from: Some(0f64),
}, to: Some(0.1f64),
RangeAggregationRange { },
key: None, RangeAggregationRange {
from: Some(0.1f64), key: None,
to: Some(0.2f64), from: Some(0.1f64),
}, to: Some(0.2f64),
], },
keyed: false, ],
}), keyed: false,
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -642,25 +654,28 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"date_ranges".to_string(), "date_ranges".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Range(RangeAggregation { BucketAggregation {
field: "date".to_string(), bucket_agg: BucketAggregationType::Range(RangeAggregation {
ranges: vec![ field: "date".to_string(),
RangeAggregationRange { ranges: vec![
key: None, RangeAggregationRange {
from: None, key: None,
to: Some(1546300800000000.0f64), from: None,
}, to: Some(1546300800000000.0f64),
RangeAggregationRange { },
key: None, RangeAggregationRange {
from: Some(1546300800000000.0f64), key: None,
to: Some(1546387200000000.0f64), from: Some(1546300800000000.0f64),
}, to: Some(1546387200000000.0f64),
], },
keyed: false, ],
}), keyed: false,
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -704,18 +719,21 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"range".to_string(), "range".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Range(RangeAggregation { BucketAggregation {
field: "fraction_f64".to_string(), bucket_agg: BucketAggregationType::Range(RangeAggregation {
ranges: vec![RangeAggregationRange { field: "fraction_f64".to_string(),
key: Some("custom-key-0-to-0.1".to_string()), ranges: vec![RangeAggregationRange {
from: Some(0f64), key: Some("custom-key-0-to-0.1".to_string()),
to: Some(0.1f64), from: Some(0f64),
}], to: Some(0.1f64),
keyed: true, }],
}), keyed: true,
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();

View File

@@ -559,13 +559,16 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
..Default::default() field: "string_id".to_string(),
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -581,15 +584,18 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
size: Some(2), field: "string_id".to_string(),
split_size: Some(2), size: Some(2),
..Default::default() split_size: Some(2),
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -608,15 +614,18 @@ mod tests {
// test min_doc_count // test min_doc_count
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
size: Some(2), field: "string_id".to_string(),
min_doc_count: Some(3), size: Some(2),
..Default::default() min_doc_count: Some(3),
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -676,17 +685,20 @@ mod tests {
// sub agg desc // sub agg desc
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "string_id".to_string(),
order: Order::Asc, order: Some(CustomOrder {
target: OrderTarget::Count, order: Order::Asc,
target: OrderTarget::Count,
}),
..Default::default()
}), }),
..Default::default() sub_aggregation: sub_agg.clone(),
}), }
sub_aggregation: sub_agg.clone(), .into(),
}), ),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -711,45 +723,54 @@ mod tests {
let agg_req: Aggregations = vec![ let agg_req: Aggregations = vec![
( (
"my_scores1".to_string(), "my_scores1".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "score".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "score".to_string(),
order: Order::Asc, order: Some(CustomOrder {
target: OrderTarget::Count, 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(), "my_scores2".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "score_f64".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "score_f64".to_string(),
order: Order::Asc, order: Some(CustomOrder {
target: OrderTarget::Count, 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(), "my_scores3".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "score_i64".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "score_i64".to_string(),
order: Order::Asc, order: Some(CustomOrder {
target: OrderTarget::Count, order: Order::Asc,
target: OrderTarget::Count,
}),
..Default::default()
}), }),
..Default::default() sub_aggregation: sub_agg,
}), }
sub_aggregation: sub_agg, .into(),
}), ),
), ),
] ]
.into_iter() .into_iter()
@@ -850,17 +871,20 @@ mod tests {
// sub agg desc // sub agg desc
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "string_id".to_string(),
order: Order::Desc, order: Some(CustomOrder {
target: OrderTarget::SubAggregation("avg_score".to_string()), 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() .into_iter()
.collect(); .collect();
@@ -883,17 +907,20 @@ mod tests {
// sub agg asc // sub agg asc
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "string_id".to_string(),
order: Order::Asc, order: Some(CustomOrder {
target: OrderTarget::SubAggregation("avg_score".to_string()), 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() .into_iter()
.collect(); .collect();
@@ -917,17 +944,20 @@ mod tests {
// sub agg multi value asc // sub agg multi value asc
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "string_id".to_string(),
order: Order::Asc, order: Some(CustomOrder {
target: OrderTarget::SubAggregation("stats_score.avg".to_string()), 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() .into_iter()
.collect(); .collect();
@@ -951,17 +981,20 @@ mod tests {
// sub agg invalid request // sub agg invalid request
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "string_id".to_string(),
order: Order::Asc, order: Some(CustomOrder {
target: OrderTarget::SubAggregation("doesnotexist".to_string()), order: Order::Asc,
target: OrderTarget::SubAggregation("doesnotexist".to_string()),
}),
..Default::default()
}), }),
..Default::default() sub_aggregation: sub_agg,
}), }
sub_aggregation: sub_agg, .into(),
}), ),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -998,17 +1031,20 @@ mod tests {
// key asc // key asc
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "string_id".to_string(),
order: Order::Asc, order: Some(CustomOrder {
target: OrderTarget::Key, order: Order::Asc,
target: OrderTarget::Key,
}),
..Default::default()
}), }),
..Default::default() sub_aggregation: Default::default(),
}), }
sub_aggregation: Default::default(), .into(),
}), ),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1025,18 +1061,21 @@ mod tests {
// key desc and size cut_off // key desc and size cut_off
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "string_id".to_string(),
order: Order::Asc, order: Some(CustomOrder {
target: OrderTarget::Key, order: Order::Asc,
target: OrderTarget::Key,
}),
size: Some(2),
..Default::default()
}), }),
size: Some(2), sub_aggregation: Default::default(),
..Default::default() }
}), .into(),
sub_aggregation: Default::default(), ),
}),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1056,19 +1095,22 @@ mod tests {
// key asc and segment_size cut_off // key asc and segment_size cut_off
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "string_id".to_string(),
order: Order::Asc, order: Some(CustomOrder {
target: OrderTarget::Key, order: Order::Asc,
target: OrderTarget::Key,
}),
size: Some(2),
segment_size: Some(2),
..Default::default()
}), }),
size: Some(2), sub_aggregation: Default::default(),
segment_size: Some(2), }
..Default::default() .into(),
}), ),
sub_aggregation: Default::default(),
}),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1086,17 +1128,20 @@ mod tests {
// key desc // key desc
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "string_id".to_string(),
order: Order::Desc, order: Some(CustomOrder {
target: OrderTarget::Key, order: Order::Desc,
target: OrderTarget::Key,
}),
..Default::default()
}), }),
..Default::default() sub_aggregation: Default::default(),
}), }
sub_aggregation: Default::default(), .into(),
}), ),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1113,18 +1158,21 @@ mod tests {
// key desc, size cut_off // key desc, size cut_off
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "string_id".to_string(),
order: Order::Desc, order: Some(CustomOrder {
target: OrderTarget::Key, order: Order::Desc,
target: OrderTarget::Key,
}),
size: Some(2),
..Default::default()
}), }),
size: Some(2), sub_aggregation: Default::default(),
..Default::default() }
}), .into(),
sub_aggregation: Default::default(), ),
}),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1143,19 +1191,22 @@ mod tests {
// key desc, segment_size cut_off // key desc, segment_size cut_off
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
order: Some(CustomOrder { field: "string_id".to_string(),
order: Order::Desc, order: Some(CustomOrder {
target: OrderTarget::Key, order: Order::Desc,
target: OrderTarget::Key,
}),
size: Some(2),
segment_size: Some(2),
..Default::default()
}), }),
size: Some(2), sub_aggregation: Default::default(),
segment_size: Some(2), }
..Default::default() .into(),
}), ),
sub_aggregation: Default::default(),
}),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1184,14 +1235,17 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
min_doc_count: Some(0), field: "string_id".to_string(),
..Default::default() min_doc_count: Some(0),
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1224,15 +1278,18 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
size: Some(2), field: "string_id".to_string(),
segment_size: Some(2), size: Some(2),
..Default::default() segment_size: Some(2),
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1254,16 +1311,19 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
size: Some(2), field: "string_id".to_string(),
segment_size: Some(2), size: Some(2),
show_term_doc_count_error: Some(false), segment_size: Some(2),
..Default::default() show_term_doc_count_error: Some(false),
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1316,14 +1376,17 @@ mod tests {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"my_texts".to_string(), "my_texts".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "text_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
min_doc_count: Some(0), field: "text_id".to_string(),
..Default::default() min_doc_count: Some(0),
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1344,19 +1407,22 @@ mod tests {
fn test_json_format() -> crate::Result<()> { fn test_json_format() -> crate::Result<()> {
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"term_agg_test".to_string(), "term_agg_test".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
size: Some(2), field: "string_id".to_string(),
segment_size: Some(2), size: Some(2),
order: Some(CustomOrder { segment_size: Some(2),
target: OrderTarget::Key, order: Some(CustomOrder {
order: Order::Desc, target: OrderTarget::Key,
order: Order::Desc,
}),
..Default::default()
}), }),
..Default::default() sub_aggregation: Default::default(),
}), }
sub_aggregation: Default::default(), .into(),
}), ),
)] )]
.into_iter() .into_iter()
.collect(); .collect();
@@ -1391,14 +1457,17 @@ mod tests {
// test alias shard_size, split_size // test alias shard_size, split_size
let agg_req: Aggregations = vec![( let agg_req: Aggregations = vec![(
"term_agg_test".to_string(), "term_agg_test".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "string_id".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
split_size: Some(2), field: "string_id".to_string(),
..Default::default() split_size: Some(2),
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();

View File

@@ -380,24 +380,27 @@ mod tests {
), ),
( (
"range".to_string(), "range".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Range(RangeAggregation { BucketAggregation {
field: "score".to_string(), bucket_agg: BucketAggregationType::Range(RangeAggregation {
ranges: vec![ field: "score".to_string(),
(3f64..7f64).into(), ranges: vec![
(7f64..19f64).into(), (3f64..7f64).into(),
(19f64..20f64).into(), (7f64..19f64).into(),
], (19f64..20f64).into(),
..Default::default() ],
}), ..Default::default()
sub_aggregation: iter::once(( }),
"stats".to_string(), sub_aggregation: iter::once((
Aggregation::Metric(MetricAggregation::Stats( "stats".to_string(),
StatsAggregation::from_field_name("score".to_string()), Aggregation::Metric(MetricAggregation::Stats(
)), StatsAggregation::from_field_name("score".to_string()),
)) )),
.collect(), ))
}), .collect(),
}
.into(),
),
), ),
] ]
.into_iter() .into_iter()

View File

@@ -130,14 +130,14 @@
//! let agg_req_1: Aggregations = vec![ //! let agg_req_1: Aggregations = vec![
//! ( //! (
//! "range".to_string(), //! "range".to_string(),
//! Aggregation::Bucket(BucketAggregation { //! Aggregation::Bucket(Box::new(BucketAggregation {
//! bucket_agg: BucketAggregationType::Range(RangeAggregation{ //! bucket_agg: BucketAggregationType::Range(RangeAggregation{
//! field: "score".to_string(), //! field: "score".to_string(),
//! ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()], //! ranges: vec![(3f64..7f64).into(), (7f64..20f64).into()],
//! keyed: false, //! keyed: false,
//! }), //! }),
//! sub_aggregation: sub_agg_req_1.clone(), //! sub_aggregation: sub_agg_req_1.clone(),
//! }), //! })),
//! ), //! ),
//! ] //! ]
//! .into_iter() //! .into_iter()
@@ -614,13 +614,16 @@ mod tests {
let searcher = reader.searcher(); let searcher = reader.searcher();
let agg: Aggregations = vec![( let agg: Aggregations = vec![(
"jsonagg".to_string(), "jsonagg".to_string(),
Aggregation::Bucket(BucketAggregation { Aggregation::Bucket(
bucket_agg: BucketAggregationType::Terms(TermsAggregation { BucketAggregation {
field: "json.color".to_string(), bucket_agg: BucketAggregationType::Terms(TermsAggregation {
..Default::default() field: "json.color".to_string(),
}), ..Default::default()
sub_aggregation: Default::default(), }),
}), sub_aggregation: Default::default(),
}
.into(),
),
)] )]
.into_iter() .into_iter()
.collect(); .collect();