33namespace PDPhilip \Elasticsearch \DSL ;
44
55use Elastic \Elasticsearch \Exception \ClientResponseException ;
6+ use Elastic \Elasticsearch \Exception \MissingParameterException ;
67use Elastic \Elasticsearch \Exception \ServerResponseException ;
78use Exception ;
8- use Elastic \Elasticsearch \ClientBuilder ;
99use Elastic \Elasticsearch \Client ;
1010
1111
@@ -90,6 +90,7 @@ public function processIndicesDsl($method, $params): Results
9090 */
9191 public function processFind ($ wheres , $ options , $ columns ): Results
9292 {
93+
9394 $ params = $ this ->buildParams ($ this ->index , $ wheres , $ options , $ columns );
9495
9596 return $ this ->_returnSearch ($ params , __FUNCTION__ );
@@ -100,6 +101,7 @@ public function processFind($wheres, $options, $columns): Results
100101 */
101102 public function processSearch ($ searchParams , $ searchOptions , $ wheres , $ opts , $ fields , $ cols )
102103 {
104+
103105 $ params = $ this ->buildSearchParams ($ this ->index , $ searchParams , $ searchOptions , $ wheres , $ opts , $ fields , $ cols );
104106
105107 return $ this ->_returnSearch ($ params , __FUNCTION__ );
@@ -115,6 +117,7 @@ protected function _returnSearch($params, $source)
115117 $ process = $ this ->client ->search ($ params );
116118
117119 return $ this ->_sanitizeSearchResponse ($ process , $ params , $ this ->_queryTag ($ source ));
120+
118121 } catch (Exception $ e ) {
119122
120123 $ result = $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
@@ -347,18 +350,34 @@ public function processScript($id, $script)
347350 // Index administration
348351 //----------------------------------------------------------------------
349352
353+ /**
354+ * @throws ClientResponseException
355+ * @throws ServerResponseException
356+ * @throws MissingParameterException
357+ */
350358 public function processGetIndices ($ all ): array
351359 {
352- $ response = $ this ->client ->cat ()->indices ();
360+ $ index = $ this ->index ;
361+ if ($ all ) {
362+ $ index = '* ' ;
363+ }
364+ $ response = $ this ->client ->indices ()->get (['index ' => $ index ]);
353365
354- return $ this -> catIndices ( $ response , $ all );
366+ return $ response -> asArray ( );
355367 }
356368
357369 public function processIndexExists ($ index ): bool
358370 {
359371 $ params = ['index ' => $ index ];
360372
361- return $ this ->client ->indices ()->exists ($ params );
373+ try {
374+ $ test = $ this ->client ->indices ()->exists ($ params );
375+
376+ return $ test ->getStatusCode () == 200 ;
377+ } catch (Exception $ e ) {
378+ return false ;
379+ }
380+
362381 }
363382
364383 /**
@@ -401,9 +420,8 @@ public function processIndexSettings($index): mixed
401420 */
402421 public function processIndexCreate ($ settings )
403422 {
404-
423+ $ params = $ this -> buildIndexMap ( $ this -> index , $ settings );
405424 try {
406- $ params = $ this ->buildIndexMap ($ this ->index , $ settings );
407425 $ response = $ this ->client ->indices ()->create ($ params );
408426
409427 $ result = $ this ->_return (true , $ response , $ params , $ this ->_queryTag (__FUNCTION__ ));
@@ -462,15 +480,32 @@ public function processIndexModify($settings): bool
462480 /**
463481 * @throws Exception
464482 */
465- public function processReIndex ($ newIndex , $ oldIndex ): bool
483+ public function processReIndex ($ oldIndex , $ newIndex ): Results
466484 {
467- $ params ['source ' ]['index ' ] = $ oldIndex ;
468- $ params ['dest ' ]['index ' ] = $ newIndex ;
485+ $ prefix = str_replace ('* ' , '' , $ this ->index );
486+ if ($ prefix ) {
487+ $ oldIndex = $ prefix .'_ ' .$ oldIndex ;
488+ $ newIndex = $ prefix .'_ ' .$ newIndex ;
489+ }
490+ $ params ['body ' ]['source ' ]['index ' ] = $ oldIndex ;
491+ $ params ['body ' ]['dest ' ]['index ' ] = $ newIndex ;
469492 try {
470493 $ response = $ this ->client ->reindex ($ params );
471- $ result = $ this ->_return (true , $ response , $ params , $ this ->_queryTag (__FUNCTION__ ));
494+ $ result = $ response ->asArray ();
495+ $ resultData = [
496+ 'took ' => $ result ['took ' ],
497+ 'total ' => $ result ['total ' ],
498+ 'created ' => $ result ['created ' ],
499+ 'updated ' => $ result ['updated ' ],
500+ 'deleted ' => $ result ['deleted ' ],
501+ 'batches ' => $ result ['batches ' ],
502+ 'version_conflicts ' => $ result ['version_conflicts ' ],
503+ 'noops ' => $ result ['noops ' ],
504+ 'retries ' => $ result ['retries ' ],
505+ ];
506+
507+ return $ this ->_return ($ resultData , $ result , $ params , $ this ->_queryTag (__FUNCTION__ ));
472508
473- return true ;
474509 } catch (Exception $ e ) {
475510 $ result = $ this ->_returnError ($ e ->getMessage (), $ e ->getCode (), $ params , $ this ->_queryTag (__FUNCTION__ ));
476511 throw new Exception ($ result ->errorMessage );
0 commit comments