File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed
Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -62,8 +62,10 @@ public function toArray() : array
6262
6363 foreach ($ this ->aggregations as $ aggregation ) {
6464 if ($ aggregation instanceof \Spameri \ElasticQuery \Aggregation \LeafAggregationCollection) {
65- $ array [$ this ->key ()]['aggs ' ] = $ aggregation ->toArray ();
66-
65+ $ array [$ this ->key ()] = [
66+ 'aggs ' => $ aggregation ->toArray (),
67+ 'filter ' => $ this ->filter ->toArray (),
68+ ];
6769 } else {
6870 $ array [$ this ->key ()] = $ array + $ aggregation ->toArray ();
6971 }
Original file line number Diff line number Diff line change @@ -182,14 +182,27 @@ private function mapAggregation(
182182 , array $ aggregationArray
183183 ) : \Spameri \ElasticQuery \Response \Result \Aggregation
184184 {
185+ $ i = 0 ;
185186 $ buckets = [];
186187 $ aggregations = [];
187- foreach ($ aggregationArray ['buckets ' ] as $ bucketPosition => $ bucket ) {
188- $ buckets [] = $ this ->mapBucket ($ bucketPosition , $ bucket );
188+
189+ if (isset ($ aggregationArray ['buckets ' ])) {
190+ foreach ($ aggregationArray ['buckets ' ] as $ bucketPosition => $ bucket ) {
191+ $ buckets [] = $ this ->mapBucket ($ bucketPosition , $ bucket );
192+ }
193+ }
194+
195+ if (isset ($ aggregationArray ['doc_count ' ]) && $ aggregationArray ['doc_count ' ] > 0 ) {
196+ foreach ($ aggregationArray as $ aggregationName => $ aggregation ) {
197+ if ( ! \is_array ($ aggregation )) {
198+ continue ;
199+ }
200+ $ aggregations [] = $ this ->mapAggregation ($ aggregationName , $ i , $ aggregation );
201+ $ i ++;
202+ }
189203 }
190204
191205 if (isset ($ aggregationArray ['aggregations ' ])) {
192- $ i = 0 ;
193206 foreach ($ aggregationArray ['aggregations ' ] as $ aggregationName => $ aggregation ) {
194207 $ aggregations [] = $ this ->mapAggregation ($ aggregationName , $ i , $ aggregation );
195208 $ i ++;
You can’t perform that action at this time.
0 commit comments