@@ -120,67 +120,6 @@ public function testConnection(): bool
120
120
return $ this ->ping ();
121
121
}
122
122
123
- /**
124
- * Build config for Elasticsearch 8
125
- *
126
- * @param array $options
127
- * @return array
128
- */
129
- private function buildESConfig (array $ options = []): array
130
- {
131
- $ hostname = preg_replace ('/http[s]?:\/\//i ' , '' , $ options ['hostname ' ]);
132
- // @codingStandardsIgnoreStart
133
- $ protocol = parse_url ($ options ['hostname ' ], PHP_URL_SCHEME );
134
- // @codingStandardsIgnoreEnd
135
- if (!$ protocol ) {
136
- $ protocol = 'http ' ;
137
- }
138
-
139
- $ authString = '' ;
140
- if (!empty ($ options ['enableAuth ' ]) && (int )$ options ['enableAuth ' ] === 1 ) {
141
- $ authString = "{$ options ['username ' ]}: {$ options ['password ' ]}@ " ;
142
- }
143
-
144
- $ portString = '' ;
145
- if (!empty ($ options ['port ' ])) {
146
- $ portString = ': ' . $ options ['port ' ];
147
- }
148
-
149
- $ host = $ protocol . ':// ' . $ authString . $ hostname . $ portString ;
150
-
151
- $ options ['hosts ' ] = [$ host ];
152
-
153
- return $ options ;
154
- }
155
-
156
- /**
157
- * Performs bulk query over Elasticsearch 8 index
158
- *
159
- * @param array $query
160
- * @return void
161
- */
162
- public function bulkQuery (array $ query )
163
- {
164
- $ this ->getElasticsearchClient ()->bulk ($ query );
165
- }
166
-
167
- /**
168
- * Creates an Elasticsearch 8 index.
169
- *
170
- * @param string $index
171
- * @param array $settings
172
- * @return void
173
- */
174
- public function createIndex (string $ index , array $ settings )
175
- {
176
- $ this ->getElasticsearchClient ()->indices ()->create (
177
- [
178
- 'index ' => $ index ,
179
- 'body ' => $ settings ,
180
- ]
181
- );
182
- }
183
-
184
123
/**
185
124
* Add/update an Elasticsearch index settings.
186
125
*
@@ -198,33 +137,6 @@ public function putIndexSettings(string $index, array $settings): void
198
137
);
199
138
}
200
139
201
- /**
202
- * Delete an Elasticsearch 8 index.
203
- *
204
- * @param string $index
205
- * @return void
206
- */
207
- public function deleteIndex (string $ index )
208
- {
209
- $ this ->getElasticsearchClient ()->indices ()->delete (['index ' => $ index ]);
210
- }
211
-
212
- /**
213
- * Check if index is empty.
214
- *
215
- * @param string $index
216
- * @return bool
217
- */
218
- public function isEmptyIndex (string $ index ): bool
219
- {
220
- $ stats = $ this ->getElasticsearchClient ()->indices ()->stats (['index ' => $ index , 'metric ' => 'docs ' ]);
221
- if ($ stats ['indices ' ][$ index ]['primaries ' ]['docs ' ]['count ' ] === 0 ) {
222
- return true ;
223
- }
224
-
225
- return false ;
226
- }
227
-
228
140
/**
229
141
* Updates alias.
230
142
*
@@ -258,6 +170,39 @@ public function indexExists(string $index): bool
258
170
return $ this ->getElasticsearchClient ()->indices ()->exists (['index ' => $ index ])->asBool ();
259
171
}
260
172
173
+ /**
174
+ * Build config for Elasticsearch 8
175
+ *
176
+ * @param array $options
177
+ * @return array
178
+ */
179
+ private function buildESConfig (array $ options = []): array
180
+ {
181
+ $ hostname = preg_replace ('/http[s]?:\/\//i ' , '' , $ options ['hostname ' ]);
182
+ // @codingStandardsIgnoreStart
183
+ $ protocol = parse_url ($ options ['hostname ' ], PHP_URL_SCHEME );
184
+ // @codingStandardsIgnoreEnd
185
+ if (!$ protocol ) {
186
+ $ protocol = 'http ' ;
187
+ }
188
+
189
+ $ authString = '' ;
190
+ if (!empty ($ options ['enableAuth ' ]) && (int )$ options ['enableAuth ' ] === 1 ) {
191
+ $ authString = "{$ options ['username ' ]}: {$ options ['password ' ]}@ " ;
192
+ }
193
+
194
+ $ portString = '' ;
195
+ if (!empty ($ options ['port ' ])) {
196
+ $ portString = ': ' . $ options ['port ' ];
197
+ }
198
+
199
+ $ host = $ protocol . ':// ' . $ authString . $ hostname . $ portString ;
200
+
201
+ $ options ['hosts ' ] = [$ host ];
202
+
203
+ return $ options ;
204
+ }
205
+
261
206
/**
262
207
* Exists alias.
263
208
*
@@ -274,6 +219,34 @@ public function existsAlias(string $alias, string $index = '')
274
219
return $ this ->getElasticsearchClient ()->indices ()->existsAlias ($ params )->asBool ();
275
220
}
276
221
222
+ /**
223
+ * Performs bulk query over Elasticsearch 8 index
224
+ *
225
+ * @param array $query
226
+ * @return void
227
+ */
228
+ public function bulkQuery (array $ query )
229
+ {
230
+ $ this ->getElasticsearchClient ()->bulk ($ query );
231
+ }
232
+
233
+ /**
234
+ * Creates an Elasticsearch 8 index.
235
+ *
236
+ * @param string $index
237
+ * @param array $settings
238
+ * @return void
239
+ */
240
+ public function createIndex (string $ index , array $ settings )
241
+ {
242
+ $ this ->getElasticsearchClient ()->indices ()->create (
243
+ [
244
+ 'index ' => $ index ,
245
+ 'body ' => $ settings ,
246
+ ]
247
+ );
248
+ }
249
+
277
250
/**
278
251
* Get alias.
279
252
*
@@ -311,6 +284,33 @@ public function addFieldsMapping(array $fields, string $index, string $entityTyp
311
284
$ this ->getElasticsearchClient ()->indices ()->putMapping ($ params );
312
285
}
313
286
287
+ /**
288
+ * Delete an Elasticsearch 8 index.
289
+ *
290
+ * @param string $index
291
+ * @return void
292
+ */
293
+ public function deleteIndex (string $ index )
294
+ {
295
+ $ this ->getElasticsearchClient ()->indices ()->delete (['index ' => $ index ]);
296
+ }
297
+
298
+ /**
299
+ * Check if index is empty.
300
+ *
301
+ * @param string $index
302
+ * @return bool
303
+ */
304
+ public function isEmptyIndex (string $ index ): bool
305
+ {
306
+ $ stats = $ this ->getElasticsearchClient ()->indices ()->stats (['index ' => $ index , 'metric ' => 'docs ' ]);
307
+ if ($ stats ['indices ' ][$ index ]['primaries ' ]['docs ' ]['count ' ] === 0 ) {
308
+ return true ;
309
+ }
310
+
311
+ return false ;
312
+ }
313
+
314
314
/**
315
315
* Execute search by $query
316
316
*
0 commit comments