Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions src/aggregation/agg_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn test_aggregation_flushing(
searcher.search(&AllQuery, &collector).unwrap()
};

let res: Value = serde_json::from_str(&serde_json::to_string(&agg_res)?)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is on purpose to test JSON serialization roundtrips

let res: Value = serde_json::to_value(&agg_res)?;

assert_eq!(res["bucketsL1"]["buckets"][0]["doc_count"], 3);
assert_eq!(
Expand Down Expand Up @@ -270,7 +270,7 @@ fn test_aggregation_level1_simple() -> crate::Result<()> {
let searcher = reader.searcher();
let agg_res: AggregationResults = searcher.search(&term_query, &collector).unwrap();

let res: Value = serde_json::from_str(&serde_json::to_string(&agg_res)?)?;
let res: Value = serde_json::to_value(&agg_res)?;
assert_eq!(res["average"]["value"], 12.142857142857142);
assert_eq!(
res["range"]["buckets"],
Expand Down Expand Up @@ -304,6 +304,29 @@ fn test_aggregation_level1_simple() -> crate::Result<()> {
Ok(())
}

#[test]
fn test_aggregation_term_truncate_sum_other_doc_count() {
let index = get_test_index_2_segments(true).unwrap();
let reader = index.reader().unwrap();
let count_per_text: Aggregation = serde_json::from_value(json!({ "terms": { "field": "text", "size": 1 } })).unwrap();
let aggs: Aggregations = vec![("group_by_term_truncate".to_string(), count_per_text)]
.into_iter()
.collect();

let collector = get_collector(aggs);
let searcher = reader.searcher();
let agg_res: AggregationResults = searcher.search(&AllQuery, &collector).unwrap();

let res: Value = serde_json::to_value(&agg_res).unwrap();
assert_eq!(res, serde_json::json!({
"group_by_term_truncate": {
"buckets": [{ "doc_count": 7, "key": "cool" }],
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 2,
},
}));
}

#[test]
fn test_aggregation_level1() -> crate::Result<()> {
let index = get_test_index_2_segments(true)?;
Expand Down Expand Up @@ -342,7 +365,7 @@ fn test_aggregation_level1() -> crate::Result<()> {
let searcher = reader.searcher();
let agg_res: AggregationResults = searcher.search(&term_query, &collector).unwrap();

let res: Value = serde_json::from_str(&serde_json::to_string(&agg_res)?)?;
let res: Value = serde_json::to_value(&agg_res)?;
assert_eq!(res["average"]["value"], 12.142857142857142);
assert_eq!(res["average_f64"]["value"], 12.214285714285714);
assert_eq!(res["average_i64"]["value"], 12.142857142857142);
Expand Down Expand Up @@ -397,7 +420,7 @@ fn test_aggregation_level2(
IndexRecordOption::Basic,
);

let elasticsearch_compatible_json_req = r#"
let elasticsearch_compatible_json_req = serde_json::json!(
{
"rangef64": {
"range": {
Expand Down Expand Up @@ -450,9 +473,8 @@ fn test_aggregation_level2(
"term_agg": { "terms": { "field": "text" } }
}
}
}
"#;
let agg_req: Aggregations = serde_json::from_str(elasticsearch_compatible_json_req).unwrap();
});
let agg_req: Aggregations = serde_json::from_value(elasticsearch_compatible_json_req).unwrap();

let agg_res: AggregationResults = if use_distributed_collector {
let collector =
Expand All @@ -469,7 +491,7 @@ fn test_aggregation_level2(
searcher.search(&term_query, &collector).unwrap()
};

let res: Value = serde_json::from_str(&serde_json::to_string(&agg_res)?)?;
let res: Value = serde_json::to_value(agg_res)?;

assert_eq!(res["range"]["buckets"][1]["key"], "3-7");
assert_eq!(res["range"]["buckets"][1]["doc_count"], 2u64);
Expand Down
Loading