22
33namespace Ensi \LaravelElasticQuery \Tests \Seeds ;
44
5- use Elasticsearch \ Client ;
5+ use Ensi \ LaravelElasticQuery \ ElasticClient ;
66
77abstract class IndexSeeder
88{
@@ -13,14 +13,14 @@ abstract class IndexSeeder
1313
1414 protected bool $ recreate ;
1515
16- protected ?Client $ client ;
16+ protected ?ElasticClient $ client ;
1717
1818 public function __construct ()
1919 {
2020 $ this ->recreate = config ('tests.recreate_index ' , true );
2121 }
2222
23- public function setClient (Client $ client ): void
23+ public function setClient (ElasticClient $ client ): void
2424 {
2525 $ this ->client = $ client ;
2626 }
@@ -49,31 +49,27 @@ public function call(): void
4949
5050 protected function isIndexExists (): bool
5151 {
52- return $ this ->client ->indices ()-> exists ([ ' index ' => $ this ->indexName ] );
52+ return $ this ->client ->indicesExists ( $ this ->indexName );
5353 }
5454
5555 protected function dropIndex (): void
5656 {
57- $ this ->client
58- ->indices ()
59- ->delete (['index ' => $ this ->indexName ]);
57+ $ this ->client ->indicesDelete ($ this ->indexName );
6058 }
6159
6260 protected function createIndex (): void
6361 {
64- $ params = [' index ' => $ this -> indexName ];
62+ $ settings = [];
6563
6664 if (!empty ($ this ->mappings )) {
67- data_set ( $ params , ' body. mappings ', $ this ->mappings ) ;
65+ $ settings [ ' mappings '] = $ this ->mappings ;
6866 }
6967
7068 if (!empty ($ this ->settings )) {
71- data_set ( $ params , ' body. settings ', $ this ->settings ) ;
69+ $ settings [ ' settings '] = $ this ->settings ;
7270 }
7371
74- $ this ->client
75- ->indices ()
76- ->create ($ params );
72+ $ this ->client ->indicesCreate ($ this ->indexName , $ settings );
7773 }
7874
7975 protected function loadFixtures (): void
@@ -87,7 +83,7 @@ protected function loadFixtures(): void
8783 );
8884
8985 if ($ hasChanges ) {
90- $ this ->client ->indices ()-> refresh ([ ' index ' => $ this ->indexName ] );
86+ $ this ->client ->indicesRefresh ( $ this ->indexName );
9187 }
9288 }
9389
@@ -103,7 +99,7 @@ protected function loadFixture(string $path): bool
10399 ->flatMap (fn (array $ document , int $ index ) => $ this ->documentToCommand ($ document , $ index ))
104100 ->toArray ();
105101
106- $ this ->client ->bulk ([ ' body ' => $ body] );
102+ $ this ->client ->bulk ($ this -> indexName , $ body );
107103
108104 return true ;
109105 }
0 commit comments