@@ -629,33 +629,31 @@ public void testUpdateDocumentWithObjectAndNotObject() {
629
629
}
630
630
631
631
public static NumericMetricsAggregation .SingleValue createSingleMetricAgg (String name , Double value , String valueAsString ) {
632
- NumericMetricsAggregation .SingleValue agg = createSingleMetricAgg (value , valueAsString );
633
- when (agg .getName ()).thenReturn (name );
634
- return agg ;
635
- }
636
-
637
- public static NumericMetricsAggregation .SingleValue createSingleMetricAgg (Double value , String valueAsString ) {
638
632
NumericMetricsAggregation .SingleValue agg = mock (NumericMetricsAggregation .SingleValue .class );
639
633
when (agg .value ()).thenReturn (value );
640
634
when (agg .getValueAsString ()).thenReturn (valueAsString );
635
+ when (agg .getName ()).thenReturn (name );
641
636
return agg ;
642
637
}
643
638
644
639
public void testSingleValueAggExtractor () {
645
- Aggregation agg = createSingleMetricAgg (Double .NaN , "NaN" );
646
- assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , "double " , Collections . emptyMap ( ), "" ), is (nullValue ()));
640
+ Aggregation agg = createSingleMetricAgg ("metric" , Double .NaN , "NaN" );
641
+ assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , Collections . singletonMap ( "metric " , "double" ), "" ), is (nullValue ()));
647
642
648
- agg = createSingleMetricAgg (Double .POSITIVE_INFINITY , "NaN" );
649
- assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , "double " , Collections . emptyMap ( ), "" ), is (nullValue ()));
643
+ agg = createSingleMetricAgg ("metric" , Double .POSITIVE_INFINITY , "NaN" );
644
+ assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , Collections . singletonMap ( "metric " , "double" ), "" ), is (nullValue ()));
650
645
651
- agg = createSingleMetricAgg (100.0 , "100.0" );
652
- assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , "double " , Collections . emptyMap ( ), "" ), equalTo (100.0 ));
646
+ agg = createSingleMetricAgg ("metric" , 100.0 , "100.0" );
647
+ assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , Collections . singletonMap ( "metric " , "double" ), "" ), equalTo (100.0 ));
653
648
654
- agg = createSingleMetricAgg (100.0 , "one_hundred" );
655
- assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , "double " , Collections . emptyMap ( ), "" ), equalTo (100.0 ));
649
+ agg = createSingleMetricAgg ("metric" , 100.0 , "one_hundred" );
650
+ assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , Collections . singletonMap ( "metric " , "double" ), "" ), equalTo (100.0 ));
656
651
657
- agg = createSingleMetricAgg (100.0 , "one_hundred" );
658
- assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , "string" , Collections .emptyMap (), "" ), equalTo ("one_hundred" ));
652
+ agg = createSingleMetricAgg ("metric" , 100.0 , "one_hundred" );
653
+ assertThat (
654
+ AggregationResultUtils .getExtractor (agg ).value (agg , Collections .singletonMap ("metric" , "string" ), "" ),
655
+ equalTo ("one_hundred" )
656
+ );
659
657
}
660
658
661
659
private ScriptedMetric createScriptedMetric (Object returnValue ) {
@@ -667,14 +665,14 @@ private ScriptedMetric createScriptedMetric(Object returnValue) {
667
665
@ SuppressWarnings ("unchecked" )
668
666
public void testScriptedMetricAggExtractor () {
669
667
Aggregation agg = createScriptedMetric (null );
670
- assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , "object" , Collections .emptyMap (), "" ), is (nullValue ()));
668
+ assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" ), is (nullValue ()));
671
669
672
670
agg = createScriptedMetric (Collections .singletonList ("values" ));
673
- Object val = AggregationResultUtils .getExtractor (agg ).value (agg , "object" , Collections .emptyMap (), "" );
671
+ Object val = AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" );
674
672
assertThat ((List <String >) val , hasItem ("values" ));
675
673
676
674
agg = createScriptedMetric (Collections .singletonMap ("key" , 100 ));
677
- val = AggregationResultUtils .getExtractor (agg ).value (agg , "object" , Collections .emptyMap (), "" );
675
+ val = AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" );
678
676
assertThat (((Map <String , Object >) val ).get ("key" ), equalTo (100 ));
679
677
}
680
678
@@ -687,13 +685,13 @@ private GeoCentroid createGeoCentroid(GeoPoint point, long count) {
687
685
688
686
public void testGeoCentroidAggExtractor () {
689
687
Aggregation agg = createGeoCentroid (null , 0 );
690
- assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , "geo_point" , Collections .emptyMap (), "" ), is (nullValue ()));
688
+ assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" ), is (nullValue ()));
691
689
692
690
agg = createGeoCentroid (new GeoPoint (100.0 , 101.0 ), 0 );
693
- assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , "geo_point" , Collections .emptyMap (), "" ), is (nullValue ()));
691
+ assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" ), is (nullValue ()));
694
692
695
693
agg = createGeoCentroid (new GeoPoint (100.0 , 101.0 ), randomIntBetween (1 , 100 ));
696
- assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , "geo_point" , Collections .emptyMap (), "" ), equalTo ("100.0, 101.0" ));
694
+ assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" ), equalTo ("100.0, 101.0" ));
697
695
}
698
696
699
697
private GeoBounds createGeoBounds (GeoPoint tl , GeoPoint br ) {
@@ -707,10 +705,10 @@ private GeoBounds createGeoBounds(GeoPoint tl, GeoPoint br) {
707
705
public void testGeoBoundsAggExtractor () {
708
706
final int numberOfRuns = 25 ;
709
707
Aggregation agg = createGeoBounds (null , new GeoPoint (100.0 , 101.0 ));
710
- assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , "geo_shape" , Collections .emptyMap (), "" ), is (nullValue ()));
708
+ assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" ), is (nullValue ()));
711
709
712
710
agg = createGeoBounds (new GeoPoint (100.0 , 101.0 ), null );
713
- assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , "geo_shape" , Collections .emptyMap (), "" ), is (nullValue ()));
711
+ assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" ), is (nullValue ()));
714
712
715
713
String type = "point" ;
716
714
for (int i = 0 ; i < numberOfRuns ; i ++) {
@@ -720,10 +718,7 @@ public void testGeoBoundsAggExtractor() {
720
718
double lon = randomDoubleBetween (-180.0 , 180.0 , false );
721
719
expectedObject .put ("coordinates" , Arrays .asList (lon , lat ));
722
720
agg = createGeoBounds (new GeoPoint (lat , lon ), new GeoPoint (lat , lon ));
723
- assertThat (
724
- AggregationResultUtils .getExtractor (agg ).value (agg , "geo_shape" , Collections .emptyMap (), "" ),
725
- equalTo (expectedObject )
726
- );
721
+ assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" ), equalTo (expectedObject ));
727
722
}
728
723
729
724
type = "linestring" ;
@@ -738,7 +733,7 @@ public void testGeoBoundsAggExtractor() {
738
733
lon2 = randomDoubleBetween (-180.0 , 180.0 , false );
739
734
}
740
735
agg = createGeoBounds (new GeoPoint (lat , lon ), new GeoPoint (lat2 , lon2 ));
741
- Object val = AggregationResultUtils .getExtractor (agg ).value (agg , "geo_shape" , Collections .emptyMap (), "" );
736
+ Object val = AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" );
742
737
Map <String , Object > geoJson = (Map <String , Object >) val ;
743
738
assertThat (geoJson .get ("type" ), equalTo (type ));
744
739
List <Double []> coordinates = (List <Double []>) geoJson .get ("coordinates" );
@@ -762,7 +757,7 @@ public void testGeoBoundsAggExtractor() {
762
757
lon2 = randomDoubleBetween (-180.0 , 180.0 , false );
763
758
}
764
759
agg = createGeoBounds (new GeoPoint (lat , lon ), new GeoPoint (lat2 , lon2 ));
765
- Object val = AggregationResultUtils .getExtractor (agg ).value (agg , "geo_shape" , Collections .emptyMap (), "" );
760
+ Object val = AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" );
766
761
Map <String , Object > geoJson = (Map <String , Object >) val ;
767
762
assertThat (geoJson .get ("type" ), equalTo (type ));
768
763
List <List <Double []>> coordinates = (List <List <Double []>>) geoJson .get ("coordinates" );
@@ -798,7 +793,7 @@ public void testPercentilesAggExtractor() {
798
793
Arrays .asList (new Percentile (1 , 0 ), new Percentile (50 , 22.2 ), new Percentile (99 , 43.3 ), new Percentile (99.5 , 100.3 ))
799
794
);
800
795
assertThat (
801
- AggregationResultUtils .getExtractor (agg ).value (agg , "object" , Collections .emptyMap (), "" ),
796
+ AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" ),
802
797
equalTo (asMap ("1" , 0.0 , "50" , 22.2 , "99" , 43.3 , "99_5" , 100.3 ))
803
798
);
804
799
}
@@ -820,11 +815,11 @@ public static SingleBucketAggregation createSingleBucketAgg(String name, long do
820
815
821
816
public void testSingleBucketAggExtractor () {
822
817
Aggregation agg = createSingleBucketAgg ("sba" , 42L );
823
- assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , "long" , Collections .emptyMap (), "" ), equalTo (42L ));
818
+ assertThat (AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" ), equalTo (42L ));
824
819
825
820
agg = createSingleBucketAgg ("sba1" , 42L , createSingleMetricAgg ("sub1" , 100.0 , "100.0" ));
826
821
assertThat (
827
- AggregationResultUtils .getExtractor (agg ).value (agg , "object" , Collections .emptyMap (), "" ),
822
+ AggregationResultUtils .getExtractor (agg ).value (agg , Collections .emptyMap (), "" ),
828
823
equalTo (Collections .singletonMap ("sub1" , 100.0 ))
829
824
);
830
825
@@ -835,7 +830,7 @@ public void testSingleBucketAggExtractor() {
835
830
createSingleMetricAgg ("sub2" , 33.33 , "thirty_three" )
836
831
);
837
832
assertThat (
838
- AggregationResultUtils .getExtractor (agg ).value (agg , "object" , asStringMap ("sba2.sub1" , "long" , "sba2.sub2" , "float" ), "" ),
833
+ AggregationResultUtils .getExtractor (agg ).value (agg , asStringMap ("sba2.sub1" , "long" , "sba2.sub2" , "float" ), "" ),
839
834
equalTo (asMap ("sub1" , 100.0 , "sub2" , 33.33 ))
840
835
);
841
836
@@ -847,7 +842,7 @@ public void testSingleBucketAggExtractor() {
847
842
createSingleBucketAgg ("sub3" , 42L )
848
843
);
849
844
assertThat (
850
- AggregationResultUtils .getExtractor (agg ).value (agg , "object" , asStringMap ("sba3.sub1" , "long" , "sba3.sub2" , "double" ), "" ),
845
+ AggregationResultUtils .getExtractor (agg ).value (agg , asStringMap ("sba3.sub1" , "long" , "sba3.sub2" , "double" ), "" ),
851
846
equalTo (asMap ("sub1" , 100.0 , "sub2" , 33.33 , "sub3" , 42L ))
852
847
);
853
848
@@ -860,7 +855,7 @@ public void testSingleBucketAggExtractor() {
860
855
);
861
856
assertThat (
862
857
AggregationResultUtils .getExtractor (agg )
863
- .value (agg , "object" , asStringMap ("sba4.sub3.subsub1" , "double" , "sba4.sub2" , "float" , "sba4.sub1" , "long" ), "" ),
858
+ .value (agg , asStringMap ("sba4.sub3.subsub1" , "double" , "sba4.sub2" , "float" , "sba4.sub1" , "long" ), "" ),
864
859
equalTo (asMap ("sub1" , 100.0 , "sub2" , 33.33 , "sub3" , asMap ("subsub1" , 11.1 )))
865
860
);
866
861
}
0 commit comments