| @@ 118-149 (lines=32) @@ | ||
| 115 | /** |
|
| 116 | * @group functional |
|
| 117 | */ |
|
| 118 | public function testCompositeWithSizeAggregation(): void |
|
| 119 | { |
|
| 120 | $composite = new Composite('products'); |
|
| 121 | $composite->setSize(2); |
|
| 122 | $composite->addSource((new Terms('color'))->setField('color.keyword')); |
|
| 123 | ||
| 124 | $query = new Query(); |
|
| 125 | $query->addAggregation($composite); |
|
| 126 | ||
| 127 | $results = $this->_getIndexForTest()->search($query)->getAggregation('products'); |
|
| 128 | $expected = [ |
|
| 129 | 'after_key' => [ |
|
| 130 | 'color' => 'green', |
|
| 131 | ], |
|
| 132 | 'buckets' => [ |
|
| 133 | [ |
|
| 134 | 'key' => [ |
|
| 135 | 'color' => 'blue', |
|
| 136 | ], |
|
| 137 | 'doc_count' => 2, |
|
| 138 | ], |
|
| 139 | [ |
|
| 140 | 'key' => [ |
|
| 141 | 'color' => 'green', |
|
| 142 | ], |
|
| 143 | 'doc_count' => 1, |
|
| 144 | ], |
|
| 145 | ], |
|
| 146 | ]; |
|
| 147 | ||
| 148 | $this->assertEquals($expected, $results); |
|
| 149 | } |
|
| 150 | ||
| 151 | /** |
|
| 152 | * @group functional |
|
| @@ 184-216 (lines=33) @@ | ||
| 181 | /** |
|
| 182 | * @group functional |
|
| 183 | */ |
|
| 184 | public function testCompositeWithNullAfter(): void |
|
| 185 | { |
|
| 186 | $composite = new Composite('products'); |
|
| 187 | $composite->setSize(2); |
|
| 188 | $composite->addSource((new Terms('color'))->setField('color.keyword')); |
|
| 189 | $composite->addAfter(null); |
|
| 190 | ||
| 191 | $query = new Query(); |
|
| 192 | $query->addAggregation($composite); |
|
| 193 | ||
| 194 | $results = $this->_getIndexForTest()->search($query)->getAggregation('products'); |
|
| 195 | $expected = [ |
|
| 196 | 'after_key' => [ |
|
| 197 | 'color' => 'green', |
|
| 198 | ], |
|
| 199 | 'buckets' => [ |
|
| 200 | [ |
|
| 201 | 'key' => [ |
|
| 202 | 'color' => 'blue', |
|
| 203 | ], |
|
| 204 | 'doc_count' => 2, |
|
| 205 | ], |
|
| 206 | [ |
|
| 207 | 'key' => [ |
|
| 208 | 'color' => 'green', |
|
| 209 | ], |
|
| 210 | 'doc_count' => 1, |
|
| 211 | ], |
|
| 212 | ], |
|
| 213 | ]; |
|
| 214 | ||
| 215 | $this->assertEquals($expected, $results); |
|
| 216 | } |
|
| 217 | ||
| 218 | protected function _getIndexForTest(): Index |
|
| 219 | { |
|