@@ -31,12 +31,42 @@ protected function setUp(): void
3131
3232 public function testCreateIndex (): void
3333 {
34- $ response = Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
34+ $ response = Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
3535 $ this ->assertIsArray ($ response );
3636 $ this ->assertTrue ($ response ['acknowledged ' ]);
3737 $ this ->assertEquals (self ::TEST_INDEX , $ response ['index ' ]);
3838 }
3939
40+ public function testCreateIndexWithExplicitMapping (): void
41+ {
42+ $ response = Promise \wait (
43+ $ this ->client ->createOrUpdateIndex (
44+ self ::TEST_INDEX ,
45+ ['mappings ' => ['properties ' => ['testField ' => ['type ' => 'text ' ]]]]
46+ )
47+ );
48+ $ this ->assertIsArray ($ response );
49+ $ this ->assertTrue ($ response ['acknowledged ' ]);
50+ $ this ->assertEquals (self ::TEST_INDEX , $ response ['index ' ]);
51+ $ response = Promise \wait ($ this ->client ->getIndex (self ::TEST_INDEX ));
52+ $ this ->assertEquals ('text ' , $ response [self ::TEST_INDEX ]['mappings ' ]['properties ' ]['testField ' ]['type ' ]);
53+ }
54+
55+ public function testCreateIndexWithExplicitSettings (): void
56+ {
57+ $ response = Promise \wait (
58+ $ this ->client ->createOrUpdateIndex (
59+ self ::TEST_INDEX ,
60+ ['settings ' => ['index ' => ['mapping ' => ['total_fields ' => ['limit ' => 2000 ]]]]]
61+ )
62+ );
63+ $ this ->assertIsArray ($ response );
64+ $ this ->assertTrue ($ response ['acknowledged ' ]);
65+ $ this ->assertEquals (self ::TEST_INDEX , $ response ['index ' ]);
66+ $ response = Promise \wait ($ this ->client ->getIndex (self ::TEST_INDEX ));
67+ $ this ->assertEquals (2000 , $ response [self ::TEST_INDEX ]['settings ' ]['index ' ]['mapping ' ]['total_fields ' ]['limit ' ]);
68+ }
69+
4070 public function testIndicesExistsShouldThrow404ErrorIfIndexDoesNotExists (): void
4171 {
4272 $ this ->expectException (Error::class);
@@ -46,7 +76,7 @@ public function testIndicesExistsShouldThrow404ErrorIfIndexDoesNotExists(): void
4676
4777 public function testIndicesExistsShouldNotThrowAnErrorIfIndexExists (): void
4878 {
49- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
79+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
5080 $ response = Promise \wait ($ this ->client ->existsIndex (self ::TEST_INDEX ));
5181 $ this ->assertNull ($ response );
5282 }
@@ -68,7 +98,7 @@ public function testDocumentsIndexWithAutomaticIdCreation(): void
6898
6999 public function testDocumentsExistsShouldThrowA404ErrorIfDocumentDoesNotExists (): void
70100 {
71- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
101+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
72102 $ this ->expectException (Error::class);
73103 $ this ->expectExceptionCode (404 );
74104 Promise \wait ($ this ->client ->existsDocument (self ::TEST_INDEX , 'not-existent-doc ' ));
@@ -203,29 +233,29 @@ public function testCatHealth(): void
203233
204234 public function testRefreshOneIndex (): void
205235 {
206- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
236+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
207237 $ response = Promise \wait ($ this ->client ->refresh (self ::TEST_INDEX ));
208238 $ this ->assertCount (1 , $ response );
209239 }
210240
211241 public function testRefreshManyIndices (): void
212242 {
213- Promise \wait ($ this ->client ->createIndex ('an_index ' ));
214- Promise \wait ($ this ->client ->createIndex ('another_index ' ));
243+ Promise \wait ($ this ->client ->createOrUpdateIndex ('an_index ' ));
244+ Promise \wait ($ this ->client ->createOrUpdateIndex ('another_index ' ));
215245 $ response = Promise \wait ($ this ->client ->refresh ('an_index,another_index ' ));
216246 $ this ->assertCount (1 , $ response );
217247 }
218248
219249 public function testRefreshAllIndices (): void
220250 {
221- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
251+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
222252 $ response = Promise \wait ($ this ->client ->refresh ());
223253 $ this ->assertCount (1 , $ response );
224254 }
225255
226256 public function testSearch (): void
227257 {
228- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
258+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
229259 Promise \wait (
230260 $ this ->client ->indexDocument (self ::TEST_INDEX , 'document-id ' , ['uuid ' => 'this-is-a-uuid ' , 'payload ' => []], ['refresh ' => 'true ' ])
231261 );
@@ -243,7 +273,7 @@ public function testSearch(): void
243273
244274 public function testCount (): void
245275 {
246- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
276+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
247277 Promise \wait (
248278 $ this ->client ->indexDocument (self ::TEST_INDEX , '' , ['payload ' => []], ['refresh ' => 'true ' ])
249279 );
@@ -259,7 +289,7 @@ public function testCount(): void
259289
260290 public function testCountWithQuery (): void
261291 {
262- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
292+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
263293 Promise \wait (
264294 $ this ->client ->indexDocument (self ::TEST_INDEX , '' , ['user ' => 'kimchy ' ], ['refresh ' => 'true ' ])
265295 );
@@ -275,7 +305,7 @@ public function testCountWithQuery(): void
275305
276306 public function testBulkIndex (): void
277307 {
278- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
308+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
279309 $ body = [];
280310 $ responses = [];
281311 for ($ i = 1 ; $ i <= 1234 ; $ i ++) {
0 commit comments