@@ -116,7 +116,8 @@ protected function _returnSearch($params, $source)
116116 return $ this ->_sanitizeSearchResponse ($ process , $ params , $ this ->_queryTag ($ source ));
117117 } catch (Exception $ e ) {
118118
119- return $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag ($ source ));
119+ $ error = $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
120+ throw new Exception ($ error ->errorMessage );
120121 }
121122 }
122123
@@ -146,7 +147,8 @@ public function processDistinct($column, $wheres): Results
146147 return $ this ->_return ($ data , $ process , $ params , $ this ->_queryTag (__FUNCTION__ ));
147148 } catch (Exception $ e ) {
148149
149- return $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
150+ $ error = $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
151+ throw new Exception ($ error ->errorMessage );
150152 }
151153
152154
@@ -195,7 +197,8 @@ public function processSave($data, $refresh): Results
195197
196198 return $ this ->_return ($ savedData , $ response , $ params , $ this ->_queryTag (__FUNCTION__ ));
197199 } catch (Exception $ e ) {
198- return $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
200+ $ error = $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
201+ throw new Exception ($ error ->errorMessage );
199202 }
200203
201204
@@ -291,11 +294,13 @@ public function processIncrementMany($wheres, $newValues, $options, $refresh): R
291294
292295 public function processDeleteAll ($ wheres , $ options = []): Results
293296 {
297+ $ params = [
298+ 'index ' => $ this ->index ,
299+ 'id ' => $ wheres ['_id ' ],
300+ ];
301+
294302 if (isset ($ wheres ['_id ' ])) {
295- $ params = [
296- 'index ' => $ this ->index ,
297- 'id ' => $ wheres ['_id ' ],
298- ];
303+
299304 try {
300305 $ response = $ this ->client ->delete ($ params );
301306 $ response ['deleteCount ' ] = $ response ['result ' ] === 'deleted ' ? 1 : 0 ;
@@ -312,7 +317,8 @@ public function processDeleteAll($wheres, $options = []): Results
312317
313318 return $ this ->_return ($ response ['deleteCount ' ], $ response , $ params , $ this ->_queryTag (__FUNCTION__ ));
314319 } catch (Exception $ e ) {
315- return $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
320+ $ error = $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
321+ throw new Exception ($ error ->errorMessage );
316322 }
317323
318324 }
@@ -524,70 +530,78 @@ public function _countAggregate($wheres, $options, $columns): Results
524530
525531 private function _maxAggregate ($ wheres , $ options , $ columns ): Results
526532 {
533+ $ params = $ this ->buildParams ($ this ->index , $ wheres , $ options );
527534 try {
528- $ params = $ this -> buildParams ( $ this -> index , $ wheres , $ options );
535+
529536 $ params ['body ' ]['aggs ' ]['max_value ' ] = ParameterBuilder::maxAggregation ($ columns [0 ]);
530537 $ process = $ this ->client ->search ($ params );
531538
532539 return $ this ->_return ($ process ['aggregations ' ]['max_value ' ]['value ' ] ?? 0 , $ process , $ params , $ this ->_queryTag (__FUNCTION__ ));
533540 } catch (Exception $ e ) {
534541
535- return $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
542+ $ result = $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
543+ throw new Exception ($ result ->errorMessage );
536544 }
537545 }
538546
539547 private function _minAggregate ($ wheres , $ options , $ columns ): Results
540548 {
549+ $ params = $ this ->buildParams ($ this ->index , $ wheres , $ options );
541550 try {
542- $ params = $ this -> buildParams ( $ this -> index , $ wheres , $ options );
551+
543552 $ params ['body ' ]['aggs ' ]['min_value ' ] = ParameterBuilder::minAggregation ($ columns [0 ]);
544553 $ process = $ this ->client ->search ($ params );
545554
546555 return $ this ->_return ($ process ['aggregations ' ]['min_value ' ]['value ' ] ?? 0 , $ process , $ params , $ this ->_queryTag (__FUNCTION__ ));
547556 } catch (Exception $ e ) {
548- return $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
557+
558+ $ result = $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
559+ throw new Exception ($ result ->errorMessage );
549560 }
550561 }
551562
552563 private function _sumAggregate ($ wheres , $ options , $ columns ): Results
553564 {
554565
566+ $ params = $ this ->buildParams ($ this ->index , $ wheres , $ options );
555567 try {
556- $ params = $ this ->buildParams ($ this ->index , $ wheres , $ options );
557568 $ params ['body ' ]['aggs ' ]['sum_value ' ] = ParameterBuilder::sumAggregation ($ columns [0 ]);
558569 $ process = $ this ->client ->search ($ params );
559570
560571 return $ this ->_return ($ process ['aggregations ' ]['sum_value ' ]['value ' ] ?? 0 , $ process , $ params , $ this ->_queryTag (__FUNCTION__ ));
561572 } catch (Exception $ e ) {
562573
563- return $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
574+ $ result = $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
575+ throw new Exception ($ result ->errorMessage );
564576 }
565577
566578 }
567579
568580 private function _avgAggregate ($ wheres , $ options , $ columns ): Results
569581 {
582+ $ params = $ this ->buildParams ($ this ->index , $ wheres , $ options );
570583 try {
571- $ params = $ this ->buildParams ($ this ->index , $ wheres , $ options );
572584 $ params ['body ' ]['aggs ' ]['avg_value ' ] = ParameterBuilder::avgAggregation ($ columns [0 ]);
573585 $ process = $ this ->client ->search ($ params );
574586
575587 return $ this ->_return ($ process ['aggregations ' ]['avg_value ' ]['value ' ] ?? 0 , $ process , $ params , $ this ->_queryTag (__FUNCTION__ ));
576588 } catch (Exception $ e ) {
577- return $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
589+ $ result = $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
590+ throw new Exception ($ result ->errorMessage );
578591 }
579592 }
580593
581594 private function _matrixAggregate ($ wheres , $ options , $ columns ): Results
582595 {
596+ $ params = $ this ->buildParams ($ this ->index , $ wheres , $ options );
583597 try {
584- $ params = $ this ->buildParams ($ this ->index , $ wheres , $ options );
585598 $ params ['body ' ]['aggs ' ]['statistics ' ] = ParameterBuilder::matrixAggregation ($ columns );
586599 $ process = $ this ->client ->search ($ params );
587600
588601 return $ this ->_return ($ process ['aggregations ' ]['statistics ' ] ?? [], $ process , $ params , $ this ->_queryTag (__FUNCTION__ ));
589602 } catch (Exception $ e ) {
590- return $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
603+ $ result = $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
604+ throw new Exception ($ result ->errorMessage );
591605 }
592606
593607 }
0 commit comments