@@ -31,12 +31,42 @@ protected function setUp(): void
31
31
32
32
public function testCreateIndex (): void
33
33
{
34
- $ response = Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
34
+ $ response = Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
35
35
$ this ->assertIsArray ($ response );
36
36
$ this ->assertTrue ($ response ['acknowledged ' ]);
37
37
$ this ->assertEquals (self ::TEST_INDEX , $ response ['index ' ]);
38
38
}
39
39
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
+
40
70
public function testIndicesExistsShouldThrow404ErrorIfIndexDoesNotExists (): void
41
71
{
42
72
$ this ->expectException (Error::class);
@@ -46,7 +76,7 @@ public function testIndicesExistsShouldThrow404ErrorIfIndexDoesNotExists(): void
46
76
47
77
public function testIndicesExistsShouldNotThrowAnErrorIfIndexExists (): void
48
78
{
49
- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
79
+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
50
80
$ response = Promise \wait ($ this ->client ->existsIndex (self ::TEST_INDEX ));
51
81
$ this ->assertNull ($ response );
52
82
}
@@ -68,7 +98,7 @@ public function testDocumentsIndexWithAutomaticIdCreation(): void
68
98
69
99
public function testDocumentsExistsShouldThrowA404ErrorIfDocumentDoesNotExists (): void
70
100
{
71
- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
101
+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
72
102
$ this ->expectException (Error::class);
73
103
$ this ->expectExceptionCode (404 );
74
104
Promise \wait ($ this ->client ->existsDocument (self ::TEST_INDEX , 'not-existent-doc ' ));
@@ -203,29 +233,29 @@ public function testCatHealth(): void
203
233
204
234
public function testRefreshOneIndex (): void
205
235
{
206
- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
236
+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
207
237
$ response = Promise \wait ($ this ->client ->refresh (self ::TEST_INDEX ));
208
238
$ this ->assertCount (1 , $ response );
209
239
}
210
240
211
241
public function testRefreshManyIndices (): void
212
242
{
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 ' ));
215
245
$ response = Promise \wait ($ this ->client ->refresh ('an_index,another_index ' ));
216
246
$ this ->assertCount (1 , $ response );
217
247
}
218
248
219
249
public function testRefreshAllIndices (): void
220
250
{
221
- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
251
+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
222
252
$ response = Promise \wait ($ this ->client ->refresh ());
223
253
$ this ->assertCount (1 , $ response );
224
254
}
225
255
226
256
public function testSearch (): void
227
257
{
228
- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
258
+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
229
259
Promise \wait (
230
260
$ this ->client ->indexDocument (self ::TEST_INDEX , 'document-id ' , ['uuid ' => 'this-is-a-uuid ' , 'payload ' => []], ['refresh ' => 'true ' ])
231
261
);
@@ -243,7 +273,7 @@ public function testSearch(): void
243
273
244
274
public function testCount (): void
245
275
{
246
- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
276
+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
247
277
Promise \wait (
248
278
$ this ->client ->indexDocument (self ::TEST_INDEX , '' , ['payload ' => []], ['refresh ' => 'true ' ])
249
279
);
@@ -259,7 +289,7 @@ public function testCount(): void
259
289
260
290
public function testCountWithQuery (): void
261
291
{
262
- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
292
+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
263
293
Promise \wait (
264
294
$ this ->client ->indexDocument (self ::TEST_INDEX , '' , ['user ' => 'kimchy ' ], ['refresh ' => 'true ' ])
265
295
);
@@ -275,7 +305,7 @@ public function testCountWithQuery(): void
275
305
276
306
public function testBulkIndex (): void
277
307
{
278
- Promise \wait ($ this ->client ->createIndex (self ::TEST_INDEX ));
308
+ Promise \wait ($ this ->client ->createOrUpdateIndex (self ::TEST_INDEX ));
279
309
$ body = [];
280
310
$ responses = [];
281
311
for ($ i = 1 ; $ i <= 1234 ; $ i ++) {
0 commit comments