@@ -191,9 +191,9 @@ public function request(string $method, string $path = null, array $arguments =
191191 */
192192 public function create (): void
193193 {
194- $ indexConfiguration = $ this ->getConfiguration ();
195- $ indexCreateObject = array_filter ($ indexConfiguration , static fn ($ key ) => in_array ($ key , self ::$ allowedIndexCreateKeys , true ), ARRAY_FILTER_USE_KEY );
196- $ this ->request ('PUT ' , null , [], json_encode ($ indexCreateObject ));
194+ $ indexConfiguration = $ this ->getConfiguration () ?? [] ;
195+ $ indexCreateObject = is_array ( $ indexConfiguration ) ? array_filter ($ indexConfiguration , static fn ($ key ) => in_array ($ key , self ::$ allowedIndexCreateKeys , true ), ARRAY_FILTER_USE_KEY ) : [] ;
196+ $ this ->request ('PUT ' , null , [], $ this -> encodeRequestBody ($ indexCreateObject ));
197197 }
198198
199199 /**
@@ -227,7 +227,7 @@ public function updateSettings(): void
227227 }
228228 }
229229 if ($ updatableSettings !== []) {
230- $ this ->request ('PUT ' , '/_settings ' , [], json_encode ($ updatableSettings ));
230+ $ this ->request ('PUT ' , '/_settings ' , [], $ this -> encodeRequestBody ($ updatableSettings ));
231231 }
232232 }
233233
@@ -298,4 +298,13 @@ private function prefixName(): string
298298
299299 return $ indexConfiguration ['prefix ' ] . '- ' . $ this ->name ;
300300 }
301+
302+ private function encodeRequestBody (array $ content ): string
303+ {
304+ if (empty ($ content )) {
305+ return '' ;
306+ }
307+
308+ return json_encode ($ content );
309+ }
301310}
0 commit comments