Skip to content

Commit 32e00c2

Browse files
committed
add agg test for nested JSON
1 parent b60d862 commit 32e00c2

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/aggregation/agg_tests.rs

+59
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,65 @@ fn test_aggregation_on_json_object() {
624624
);
625625
}
626626

627+
#[test]
628+
fn test_aggregation_on_nested_json_object() {
629+
let mut schema_builder = Schema::builder();
630+
let json = schema_builder.add_json_field("json", FAST);
631+
let schema = schema_builder.build();
632+
let index = Index::create_in_ram(schema);
633+
let mut index_writer: IndexWriter = index.writer_for_tests().unwrap();
634+
index_writer
635+
.add_document(doc!(json => json!({"color.dot": "red", "color": {"nested":"red"} })))
636+
.unwrap();
637+
index_writer
638+
.add_document(doc!(json => json!({"color.dot": "blue", "color": {"nested":"blue"} })))
639+
.unwrap();
640+
index_writer.commit().unwrap();
641+
let reader = index.reader().unwrap();
642+
let searcher = reader.searcher();
643+
644+
let agg: Aggregations = serde_json::from_value(json!({
645+
"jsonagg1": {
646+
"terms": {
647+
"field": "json.color\\.dot",
648+
}
649+
},
650+
"jsonagg2": {
651+
"terms": {
652+
"field": "json.color.nested",
653+
}
654+
}
655+
656+
}))
657+
.unwrap();
658+
659+
let aggregation_collector = get_collector(agg);
660+
let aggregation_results = searcher.search(&AllQuery, &aggregation_collector).unwrap();
661+
let aggregation_res_json = serde_json::to_value(aggregation_results).unwrap();
662+
assert_eq!(
663+
&aggregation_res_json,
664+
&serde_json::json!({
665+
"jsonagg1": {
666+
"buckets": [
667+
{"doc_count": 1, "key": "blue"},
668+
{"doc_count": 1, "key": "red"}
669+
],
670+
"doc_count_error_upper_bound": 0,
671+
"sum_other_doc_count": 0
672+
},
673+
"jsonagg2": {
674+
"buckets": [
675+
{"doc_count": 1, "key": "blue"},
676+
{"doc_count": 1, "key": "red"}
677+
],
678+
"doc_count_error_upper_bound": 0,
679+
"sum_other_doc_count": 0
680+
}
681+
682+
})
683+
);
684+
}
685+
627686
#[test]
628687
fn test_aggregation_on_json_object_empty_columns() {
629688
let mut schema_builder = Schema::builder();

0 commit comments

Comments
 (0)