@@ -624,6 +624,67 @@ fn test_aggregation_on_json_object() {
624
624
) ;
625
625
}
626
626
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.blub" , 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
+ // I think "json.blub" should be "json\\.blub" to be consistent
648
+ "field" : "json.blub.color\\ .dot" ,
649
+ }
650
+ } ,
651
+ "jsonagg2" : {
652
+ "terms" : {
653
+ // I think "json.blub" should be "json\\.blub" to be consistent
654
+ "field" : "json.blub.color.nested" ,
655
+ }
656
+ }
657
+
658
+ } ) )
659
+ . unwrap ( ) ;
660
+
661
+ let aggregation_collector = get_collector ( agg) ;
662
+ let aggregation_results = searcher. search ( & AllQuery , & aggregation_collector) . unwrap ( ) ;
663
+ let aggregation_res_json = serde_json:: to_value ( aggregation_results) . unwrap ( ) ;
664
+ assert_eq ! (
665
+ & aggregation_res_json,
666
+ & serde_json:: json!( {
667
+ "jsonagg1" : {
668
+ "buckets" : [
669
+ { "doc_count" : 1 , "key" : "blue" } ,
670
+ { "doc_count" : 1 , "key" : "red" }
671
+ ] ,
672
+ "doc_count_error_upper_bound" : 0 ,
673
+ "sum_other_doc_count" : 0
674
+ } ,
675
+ "jsonagg2" : {
676
+ "buckets" : [
677
+ { "doc_count" : 1 , "key" : "blue" } ,
678
+ { "doc_count" : 1 , "key" : "red" }
679
+ ] ,
680
+ "doc_count_error_upper_bound" : 0 ,
681
+ "sum_other_doc_count" : 0
682
+ }
683
+
684
+ } )
685
+ ) ;
686
+ }
687
+
627
688
#[ test]
628
689
fn test_aggregation_on_json_object_empty_columns ( ) {
629
690
let mut schema_builder = Schema :: builder ( ) ;
0 commit comments