File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
src/Aggregation/Bucketing
tests/Unit/Aggregation/Bucketing Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ function ($v) {
9090 }
9191 );
9292
93- if (! empty ( $ key) ) {
93+ if ('' !== $ key ) {
9494 $ range ['key ' ] = $ key ;
9595 }
9696
Original file line number Diff line number Diff line change @@ -40,6 +40,41 @@ public function testRangeAggregationAddRange()
4040 $ this ->assertEquals ($ result , $ aggregation ->toArray ());
4141 }
4242
43+ public function testRangeAggregationAddZeroIndexedKeys ()
44+ {
45+ $ aggregation = new RangeAggregation ('test_agg ' );
46+ $ aggregation ->setKeyed (true );
47+ $ aggregation ->setField ('test_field ' );
48+ $ aggregation ->addRange (0 , 100 , '0 ' );
49+ $ aggregation ->addRange (100 , 200 , '1 ' );
50+ $ aggregation ->addRange (200 , 300 );
51+
52+ $ result = [
53+ 'range ' => [
54+ 'field ' => 'test_field ' ,
55+ 'ranges ' => [
56+ [
57+ 'from ' => 0 ,
58+ 'to ' => 100 ,
59+ 'key ' => '0 '
60+ ],
61+ [
62+ 'from ' => 100 ,
63+ 'to ' => 200 ,
64+ 'key ' => '1 '
65+ ],
66+ [
67+ 'from ' => 200 ,
68+ 'to ' => 300
69+ ]
70+ ],
71+ 'keyed ' => true
72+ ],
73+ ];
74+
75+ $ this ->assertEquals ($ result , $ aggregation ->toArray ());
76+ }
77+
4378 /**
4479 * Test addRange method with multiple values.
4580 */
You can’t perform that action at this time.
0 commit comments