kuzzle 2.31.0 → 2.32.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +1 -0
  3. package/lib/api/controllers/authController.d.ts +3 -2
  4. package/lib/api/funnel.js +2 -1
  5. package/lib/config/default.config.js +1 -0
  6. package/lib/core/backend/backendStorage.d.ts +3 -5
  7. package/lib/core/backend/backendStorage.js +8 -10
  8. package/lib/core/plugin/pluginContext.d.ts +2 -3
  9. package/lib/core/plugin/pluginContext.js +6 -4
  10. package/lib/core/security/tokenRepository.d.ts +1 -1
  11. package/lib/core/security/tokenRepository.js +1 -1
  12. package/lib/core/shared/ObjectRepository.d.ts +1 -1
  13. package/lib/core/storage/clientAdapter.js +6 -4
  14. package/lib/core/storage/storageEngine.js +4 -5
  15. package/lib/kerror/index.js +1 -1
  16. package/lib/kuzzle/event/KuzzleEventEmitter.d.ts +70 -0
  17. package/lib/kuzzle/event/KuzzleEventEmitter.js +328 -0
  18. package/lib/kuzzle/index.d.ts +3 -0
  19. package/lib/kuzzle/index.js +7 -4
  20. package/lib/kuzzle/kuzzle.d.ts +32 -19
  21. package/lib/kuzzle/kuzzle.js +31 -31
  22. package/lib/service/storage/{elasticsearch.d.ts → 7/elasticsearch.d.ts} +40 -22
  23. package/lib/service/storage/{elasticsearch.js → 7/elasticsearch.js} +24 -43
  24. package/lib/service/storage/{esWrapper.js → 7/esWrapper.js} +6 -4
  25. package/lib/service/storage/8/elasticsearch.d.ts +972 -0
  26. package/lib/service/storage/8/elasticsearch.js +2925 -0
  27. package/lib/service/storage/8/esWrapper.js +303 -0
  28. package/lib/service/storage/Elasticsearch.d.ts +9 -0
  29. package/lib/service/storage/Elasticsearch.js +48 -0
  30. package/lib/service/storage/commons/queryTranslator.d.ts +5 -0
  31. package/lib/service/storage/commons/queryTranslator.js +189 -0
  32. package/lib/types/EventHandler.d.ts +29 -1
  33. package/lib/types/config/KuzzleConfiguration.d.ts +2 -1
  34. package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +6 -2
  35. package/lib/types/storage/{Elasticsearch.d.ts → 7/Elasticsearch.d.ts} +1 -1
  36. package/lib/types/storage/8/Elasticsearch.d.ts +59 -0
  37. package/lib/types/storage/8/Elasticsearch.js +3 -0
  38. package/package.json +7 -4
  39. package/lib/kuzzle/event/kuzzleEventEmitter.js +0 -405
  40. package/lib/service/storage/queryTranslator.js +0 -219
  41. /package/lib/types/storage/{Elasticsearch.js → 7/Elasticsearch.js} +0 -0
@@ -0,0 +1,972 @@
1
+ import _ from "lodash";
2
+ import { Client, estypes } from "sdk-es8";
3
+ import { InfoResult, JSONObject, KRequestBody, KRequestParams, KStats, KUpdateResponse } from "../../../types/storage/8/Elasticsearch";
4
+ import ESWrapper from "./esWrapper";
5
+ import { QueryTranslator } from "../commons/queryTranslator";
6
+ import { storeScopeEnum } from "../../../core/storage/storeScopeEnum";
7
+ /**
8
+ * @param {Kuzzle} kuzzle kuzzle instance
9
+ * @param {Object} config Service configuration
10
+ * @param {storeScopeEnum} scope
11
+ * @constructor
12
+ */
13
+ export declare class ES8 {
14
+ _client: Client;
15
+ _scope: storeScopeEnum;
16
+ _indexPrefix: string;
17
+ _esWrapper: ESWrapper;
18
+ _esVersion: any;
19
+ _translator: QueryTranslator;
20
+ searchBodyKeys: string[];
21
+ scriptKeys: string[];
22
+ scriptAllowedArgs: string[];
23
+ maxScrollDuration: number;
24
+ scrollTTL: number;
25
+ _config: any;
26
+ constructor(config: any, scope?: storeScopeEnum);
27
+ get scope(): storeScopeEnum;
28
+ /**
29
+ * Initializes the elasticsearch client
30
+ *
31
+ * @override
32
+ * @returns {Promise}
33
+ */
34
+ _initSequence(): Promise<void>;
35
+ /**
36
+ * Translate Koncorde filters to Elasticsearch query
37
+ *
38
+ * @param {Object} filters - Set of valid Koncorde filters
39
+ * @returns {Object} Equivalent Elasticsearch query
40
+ */
41
+ translateKoncordeFilters(filters: any): any;
42
+ /**
43
+ * Returns some basic information about this service
44
+ * @override
45
+ *
46
+ * @returns {Promise.<InfoResult>} service informations
47
+ */
48
+ info(): Promise<InfoResult>;
49
+ /**
50
+ * Returns detailed multi-level storage stats data
51
+ *
52
+ * @returns {Promise.<Object>}
53
+ */
54
+ stats(): Promise<KStats>;
55
+ /**
56
+ * Scrolls results from previous elasticsearch query.
57
+ * Automatically clears the scroll context after the last result page has
58
+ * been fetched.
59
+ *
60
+ * @param {String} scrollId - Scroll identifier
61
+ * @param {Object} options - scrollTTL (default scrollTTL)
62
+ *
63
+ * @returns {Promise.<{ scrollId, hits, aggregations, total }>}
64
+ */
65
+ scroll(scrollId: string, { scrollTTL }?: {
66
+ scrollTTL?: string;
67
+ }): Promise<{
68
+ aggregations: any;
69
+ hits: {
70
+ _id: any;
71
+ _score: any;
72
+ _source: any;
73
+ collection: any;
74
+ highlight: any;
75
+ index: any;
76
+ inner_hits: {};
77
+ }[];
78
+ remaining: number;
79
+ scrollId: any;
80
+ suggest: any;
81
+ total: any;
82
+ }>;
83
+ /**
84
+ * Searches documents from elasticsearch with a query
85
+ *
86
+ * @param {String} index - Index name
87
+ * @param {String} collection - Collection name
88
+ * @param {Object} searchBody - Search request body (query, sort, etc.)
89
+ * @param {Object} options - from (undefined), size (undefined), scroll (undefined)
90
+ *
91
+ * @returns {Promise.<{ scrollId, hits, aggregations, suggest, total }>}
92
+ */
93
+ search({ index, collection, searchBody, targets, }?: {
94
+ index?: string;
95
+ collection?: string;
96
+ searchBody?: JSONObject;
97
+ targets?: any[];
98
+ }, { from, size, scroll, }?: {
99
+ from?: number;
100
+ size?: number;
101
+ scroll?: string;
102
+ }): Promise<{
103
+ aggregations: any;
104
+ hits: {
105
+ _id: any;
106
+ _score: any;
107
+ _source: any;
108
+ collection: any;
109
+ highlight: any;
110
+ index: any;
111
+ inner_hits: {};
112
+ }[];
113
+ remaining: number;
114
+ scrollId: any;
115
+ suggest: any;
116
+ total: any;
117
+ }>;
118
+ /**
119
+ * Generate a map that associate an alias to a pair of index and collection
120
+ *
121
+ * @param {*} targets
122
+ * @returns
123
+ */
124
+ _mapTargetsToAlias(targets: any): {};
125
+ _formatSearchResult(body: any, remaining?: number, searchInfo?: any): Promise<{
126
+ aggregations: any;
127
+ hits: {
128
+ _id: any;
129
+ _score: any;
130
+ _source: any;
131
+ collection: any;
132
+ highlight: any;
133
+ index: any;
134
+ inner_hits: {};
135
+ }[];
136
+ remaining: number;
137
+ scrollId: any;
138
+ suggest: any;
139
+ total: any;
140
+ }>;
141
+ /**
142
+ * Gets the document with given ID
143
+ *
144
+ * @param {String} index - Index name
145
+ * @param {String} collection - Collection name
146
+ * @param {String} id - Document ID
147
+ *
148
+ * @returns {Promise.<{ _id, _version, _source }>}
149
+ */
150
+ get(index: any, collection: any, id: any): Promise<any>;
151
+ /**
152
+ * Returns the list of documents matching the ids given in the body param
153
+ * NB: Due to internal Kuzzle mechanism, can only be called on a single
154
+ * index/collection, using the body { ids: [.. } syntax.
155
+ *
156
+ * @param {String} index - Index name
157
+ * @param {String} collection - Collection name
158
+ * @param {Array.<String>} ids - Document IDs
159
+ *
160
+ * @returns {Promise.<{ items: Array<{ _id, _source, _version }>, errors }>}
161
+ */
162
+ mGet(index: string, collection: string, ids: string[]): Promise<{
163
+ errors: any[];
164
+ item: any[];
165
+ items?: undefined;
166
+ } | {
167
+ errors: any[];
168
+ items: any[];
169
+ item?: undefined;
170
+ }>;
171
+ /**
172
+ * Counts how many documents match the filter given in body
173
+ *
174
+ * @param {String} index - Index name
175
+ * @param {String} collection - Collection name
176
+ * @param {Object} searchBody - Search request body (query, sort, etc.)
177
+ *
178
+ * @returns {Promise.<Number>} count
179
+ */
180
+ count(index: string, collection: string, searchBody?: {}): Promise<number>;
181
+ /**
182
+ * Sends the new document to elasticsearch
183
+ * Cleans data to match elasticsearch specifications
184
+ *
185
+ * @param {String} index - Index name
186
+ * @param {String} collection - Collection name
187
+ * @param {Object} content - Document content
188
+ * @param {Object} options - id (undefined), refresh (undefined), userId (null)
189
+ *
190
+ * @returns {Promise.<Object>} { _id, _version, _source }
191
+ */
192
+ create(index: string, collection: string, content: JSONObject, { id, refresh, userId, injectKuzzleMeta, }?: {
193
+ id?: string;
194
+ refresh?: boolean | "wait_for";
195
+ userId?: string;
196
+ injectKuzzleMeta?: boolean;
197
+ }): Promise<{
198
+ _id: string;
199
+ _source: KRequestBody<JSONObject>;
200
+ _version: number;
201
+ }>;
202
+ /**
203
+ * Creates a new document to Elasticsearch, or replace it if it already exist
204
+ *
205
+ * @param {String} index - Index name
206
+ * @param {String} collection - Collection name
207
+ * @param {String} id - Document id
208
+ * @param {Object} content - Document content
209
+ * @param {Object} options - refresh (undefined), userId (null), injectKuzzleMeta (true)
210
+ *
211
+ * @returns {Promise.<Object>} { _id, _version, _source, created }
212
+ */
213
+ createOrReplace(index: any, collection: any, id: any, content: any, { refresh, userId, injectKuzzleMeta, }?: {
214
+ refresh?: boolean | "wait_for";
215
+ userId?: string;
216
+ injectKuzzleMeta?: boolean;
217
+ }): Promise<{
218
+ _id: string;
219
+ _source: KRequestBody<JSONObject>;
220
+ _version: number;
221
+ created: boolean;
222
+ }>;
223
+ /**
224
+ * Sends the partial document to elasticsearch with the id to update
225
+ *
226
+ * @param {String} index - Index name
227
+ * @param {String} collection - Collection name
228
+ * @param {String} id - Document id
229
+ * @param {Object} content - Updated content
230
+ * @param {Object} options - refresh (undefined), userId (null), retryOnConflict (0)
231
+ *
232
+ * @returns {Promise.<{ _id, _version }>}
233
+ */
234
+ update(index: string, collection: string, id: string, content: JSONObject, { refresh, userId, retryOnConflict, injectKuzzleMeta, }?: {
235
+ refresh?: boolean | "wait_for";
236
+ userId?: string;
237
+ retryOnConflict?: number;
238
+ injectKuzzleMeta?: boolean;
239
+ }): Promise<KUpdateResponse>;
240
+ /**
241
+ * Sends the partial document to elasticsearch with the id to update
242
+ * Creates the document if it doesn't already exist
243
+ *
244
+ * @param {String} index - Index name
245
+ * @param {String} collection - Collection name
246
+ * @param {String} id - Document id
247
+ * @param {Object} content - Updated content
248
+ * @param {Object} options - defaultValues ({}), refresh (undefined), userId (null), retryOnConflict (0)
249
+ *
250
+ * @returns {Promise.<{ _id, _version }>}
251
+ */
252
+ upsert(index: string, collection: string, id: string, content: JSONObject, { defaultValues, refresh, userId, retryOnConflict, injectKuzzleMeta, }?: {
253
+ defaultValues?: JSONObject;
254
+ refresh?: boolean | "wait_for";
255
+ userId?: string;
256
+ retryOnConflict?: number;
257
+ injectKuzzleMeta?: boolean;
258
+ }): Promise<{
259
+ _id: string;
260
+ _source: unknown;
261
+ _version: number;
262
+ created: boolean;
263
+ }>;
264
+ /**
265
+ * Replaces a document to Elasticsearch
266
+ *
267
+ * @param {String} index - Index name
268
+ * @param {String} collection - Collection name
269
+ * @param {String} id - Document id
270
+ * @param {Object} content - Document content
271
+ * @param {Object} options - refresh (undefined), userId (null)
272
+ *
273
+ * @returns {Promise.<{ _id, _version, _source }>}
274
+ */
275
+ replace(index: string, collection: string, id: string, content: JSONObject, { refresh, userId, injectKuzzleMeta, }?: {
276
+ refresh?: boolean | "wait_for";
277
+ userId?: string;
278
+ injectKuzzleMeta?: boolean;
279
+ }): Promise<{
280
+ _id: string;
281
+ _source: KRequestBody<JSONObject>;
282
+ _version: number;
283
+ }>;
284
+ /**
285
+ * Sends to elasticsearch the document id to delete
286
+ *
287
+ * @param {String} index - Index name
288
+ * @param {String} collection - Collection name
289
+ * @param {String} id - Document id
290
+ * @param {Object} options - refresh (undefined)
291
+ *
292
+ * @returns {Promise}
293
+ */
294
+ delete(index: string, collection: string, id: string, { refresh, }?: {
295
+ refresh?: boolean | "wait_for";
296
+ }): Promise<any>;
297
+ /**
298
+ * Deletes all documents matching the provided filters.
299
+ * If fetch=false, the max documents write limit is not applied.
300
+ *
301
+ * Options:
302
+ * - size: size of the batch to retrieve documents (no-op if fetch=false)
303
+ * - refresh: refresh option for ES
304
+ * - fetch: if true, will fetch the documents before delete them
305
+ *
306
+ * @param {String} index - Index name
307
+ * @param {String} collection - Collection name
308
+ * @param {Object} query - Query to match documents
309
+ * @param {Object} options - size (undefined), refresh (undefined), fetch (true)
310
+ *
311
+ * @returns {Promise.<{ documents, total, deleted, failures: Array<{ id, reason }> }>}
312
+ */
313
+ deleteByQuery(index: string, collection: string, query: JSONObject, { refresh, size, fetch, }?: {
314
+ refresh?: boolean | "wait_for";
315
+ size?: number;
316
+ fetch?: boolean;
317
+ }): Promise<{
318
+ deleted: number;
319
+ documents: any[];
320
+ failures: {
321
+ id: string;
322
+ reason: string;
323
+ }[];
324
+ total: number;
325
+ }>;
326
+ /**
327
+ * Delete fields of a document and replace it
328
+ *
329
+ * @param {String} index - Index name
330
+ * @param {String} collection - Collection name
331
+ * @param {String} id - Document id
332
+ * @param {Array} fields - Document fields to be removed
333
+ * @param {Object} options - refresh (undefined), userId (null)
334
+ *
335
+ * @returns {Promise.<{ _id, _version, _source }>}
336
+ */
337
+ deleteFields(index: string, collection: string, id: string, fields: string, { refresh, userId, }?: {
338
+ refresh?: boolean | "wait_for";
339
+ userId?: string;
340
+ }): Promise<{
341
+ _id: string;
342
+ _source: JSONObject;
343
+ _version: number;
344
+ }>;
345
+ /**
346
+ * Updates all documents matching the provided filters
347
+ *
348
+ * @param {String} index - Index name
349
+ * @param {String} collection - Collection name
350
+ * @param {Object} query - Query to match documents
351
+ * @param {Object} changes - Changes wanted on documents
352
+ * @param {Object} options - refresh (undefined), size (undefined)
353
+ *
354
+ * @returns {Promise.<{ successes: [_id, _source, _status], errors: [ document, status, reason ] }>}
355
+ */
356
+ updateByQuery(index: string, collection: string, query: JSONObject, changes: JSONObject, { refresh, size, userId, }?: {
357
+ refresh?: boolean | "wait_for";
358
+ size?: number;
359
+ userId?: string;
360
+ }): Promise<{
361
+ errors: any;
362
+ successes: any;
363
+ }>;
364
+ /**
365
+ * Updates all documents matching the provided filters
366
+ *
367
+ * @param {String} index - Index name
368
+ * @param {String} collection - Collection name
369
+ * @param {Object} query - Query to match documents
370
+ * @param {Object} changes - Changes wanted on documents
371
+ * @param {Object} options - refresh (undefined)
372
+ *
373
+ * @returns {Promise.<{ successes: [_id, _source, _status], errors: [ document, status, reason ] }>}
374
+ */
375
+ bulkUpdateByQuery(index: string, collection: string, query: JSONObject, changes: JSONObject, { refresh, }?: {
376
+ refresh?: boolean;
377
+ }): Promise<{
378
+ updated: number;
379
+ }>;
380
+ /**
381
+ * Execute the callback with a batch of documents of specified size until all
382
+ * documents matched by the query have been processed.
383
+ *
384
+ * @param {String} index - Index name
385
+ * @param {String} collection - Collection name
386
+ * @param {Object} query - Query to match documents
387
+ * @param {Function} callback - callback that will be called with the "hits" array
388
+ * @param {Object} options - size (10), scrollTTL ('5s')
389
+ *
390
+ * @returns {Promise.<any[]>} Array of results returned by the callback
391
+ */
392
+ mExecute(index: string, collection: string, query: JSONObject, callback: any, { size, scrollTTl, }?: {
393
+ size?: number;
394
+ scrollTTl?: string;
395
+ }): Promise<any>;
396
+ /**
397
+ * Creates a new index.
398
+ *
399
+ * This methods creates an hidden collection in the provided index to be
400
+ * able to list it.
401
+ * This methods resolves if the index name does not already exists either as
402
+ * private or public index.
403
+ *
404
+ * @param {String} index - Index name
405
+ *
406
+ * @returns {Promise}
407
+ */
408
+ createIndex(index: string): Promise<any>;
409
+ /**
410
+ * Creates an empty collection.
411
+ * Mappings and settings will be applied if supplied.
412
+ *
413
+ * @param {String} index - Index name
414
+ * @param {String} collection - Collection name
415
+ * @param {Object} config - mappings ({}), settings ({})
416
+ *
417
+ * @returns {Promise}
418
+ */
419
+ createCollection(index: string, collection: string, { mappings, settings, }?: {
420
+ mappings?: estypes.MappingTypeMapping;
421
+ settings?: Record<string, any>;
422
+ }): Promise<any>;
423
+ /**
424
+ * Retrieves settings definition for index/type
425
+ *
426
+ * @param {String} index - Index name
427
+ * @param {String} collection - Collection name
428
+ *
429
+ * @returns {Promise.<{ settings }>}
430
+ */
431
+ getSettings(index: string, collection: string): Promise<estypes.IndicesIndexSettings>;
432
+ /**
433
+ * Retrieves mapping definition for index/type
434
+ *
435
+ * @param {String} index - Index name
436
+ * @param {String} collection - Collection name
437
+ * @param {Object} options - includeKuzzleMeta (false)
438
+ *
439
+ * @returns {Promise.<{ dynamic, _meta, properties }>}
440
+ */
441
+ getMapping(index: string, collection: string, { includeKuzzleMeta, }?: {
442
+ includeKuzzleMeta?: boolean;
443
+ }): Promise<{
444
+ _meta: estypes.Metadata;
445
+ dynamic: estypes.MappingDynamicMapping;
446
+ properties: Record<string, estypes.MappingProperty>;
447
+ }>;
448
+ /**
449
+ * Updates a collection mappings and settings
450
+ *
451
+ * @param {String} index - Index name
452
+ * @param {String} collection - Collection name
453
+ * @param {Object} config - mappings ({}), settings ({})
454
+ *
455
+ * @returns {Promise}
456
+ */
457
+ updateCollection(index: string, collection: string, { mappings, settings, }?: {
458
+ mappings?: estypes.MappingTypeMapping;
459
+ settings?: Record<string, any>;
460
+ }): Promise<any>;
461
+ /**
462
+ * Given index settings we return a new version of index settings
463
+ * only with allowed settings that can be set (during update or create index).
464
+ * @param indexSettings the index settings
465
+ * @returns {{index: *}} a new index settings with only allowed settings.
466
+ */
467
+ getAllowedIndexSettings(indexSettings: any): {
468
+ index: _.Omit<any, "version" | "creation_date" | "provided_name" | "uuid">;
469
+ };
470
+ /**
471
+ * Sends an empty UpdateByQuery request to update the search index
472
+ *
473
+ * @param {String} index - Index name
474
+ * @param {String} collection - Collection name
475
+ * @returns {Promise.<Object>} {}
476
+ */
477
+ updateSearchIndex(index: string, collection: string): Promise<void>;
478
+ /**
479
+ * Update a collection mappings
480
+ *
481
+ * @param {String} index - Index name
482
+ * @param {String} collection - Collection name
483
+ * @param {Object} mappings - Collection mappings in ES format
484
+ *
485
+ * @returns {Promise.<{ dynamic, _meta, properties }>}
486
+ */
487
+ updateMapping(index: string, collection: string, mappings?: estypes.MappingTypeMapping): Promise<{
488
+ dynamic: string;
489
+ _meta: JSONObject;
490
+ properties: JSONObject;
491
+ }>;
492
+ /**
493
+ * Updates a collection settings (eg: analyzers)
494
+ *
495
+ * @param {String} index - Index name
496
+ * @param {String} collection - Collection name
497
+ * @param {Object} settings - Collection settings in ES format
498
+ *
499
+ * @returns {Promise}
500
+ */
501
+ updateSettings(index: any, collection: any, settings?: {}): Promise<any>;
502
+ /**
503
+ * Empties the content of a collection. Keep the existing mapping and settings.
504
+ *
505
+ * @param {String} index - Index name
506
+ * @param {String} collection - Collection name
507
+ *
508
+ * @returns {Promise}
509
+ */
510
+ truncateCollection(index: string, collection: string): Promise<any>;
511
+ /**
512
+ * Runs several action and document
513
+ *
514
+ * @param {String} index - Index name
515
+ * @param {String} collection - Collection name
516
+ * @param {Object[]} documents - Documents to import
517
+ * @param {Object} options - timeout (undefined), refresh (undefined), userId (null)
518
+ *
519
+ * @returns {Promise.<{ items, errors }>
520
+ */
521
+ import(index: string, collection: string, documents: JSONObject[], { refresh, timeout, userId, }?: {
522
+ refresh?: boolean | "wait_for";
523
+ timeout?: string;
524
+ userId?: string;
525
+ }): Promise<{
526
+ errors: any[];
527
+ items: any[];
528
+ }>;
529
+ /**
530
+ * Retrieves the complete list of existing collections in the current index
531
+ *
532
+ * @param {String} index - Index name
533
+ * @param {Object.Boolean} includeHidden - Optional: include HIDDEN_COLLECTION in results
534
+ *
535
+ * @returns {Promise.<Array>} Collection names
536
+ */
537
+ listCollections(index: string, { includeHidden }?: {
538
+ includeHidden?: boolean;
539
+ }): Promise<any>;
540
+ /**
541
+ * Retrieves the complete list of indexes
542
+ *
543
+ * @returns {Promise.<Array>} Index names
544
+ */
545
+ listIndexes(): Promise<string[]>;
546
+ /**
547
+ * Returns an object containing the list of indexes and collections
548
+ *
549
+ * @returns {Object.<String, String[]>} Object<index, collections>
550
+ */
551
+ getSchema(): Promise<{}>;
552
+ /**
553
+ * Retrieves the complete list of aliases
554
+ *
555
+ * @returns {Promise.<Object[]>} [ { alias, index, collection, indice } ]
556
+ */
557
+ listAliases(): Promise<any[]>;
558
+ /**
559
+ * Deletes a collection
560
+ *
561
+ * @param {String} index - Index name
562
+ * @param {String} collection - Collection name
563
+ *
564
+ * @returns {Promise}
565
+ */
566
+ deleteCollection(index: string, collection: string): Promise<void>;
567
+ /**
568
+ * Deletes multiple indexes
569
+ *
570
+ * @param {String[]} indexes - Index names
571
+ *
572
+ * @returns {Promise.<String[]>}
573
+ */
574
+ deleteIndexes(indexes?: string[]): Promise<any[]>;
575
+ /**
576
+ * Deletes an index
577
+ *
578
+ * @param {String} index - Index name
579
+ *
580
+ * @returns {Promise}
581
+ */
582
+ deleteIndex(index: string): Promise<void>;
583
+ /**
584
+ * Forces a refresh on the collection.
585
+ *
586
+ * /!\ Can lead to some performance issues.
587
+ * cf https://www.elastic.co/guide/en/elasticsearch/guide/current/near-real-time.html for more details
588
+ *
589
+ * @param {String} index - Index name
590
+ * @param {String} collection - Collection name
591
+ *
592
+ * @returns {Promise.<Object>} { _shards }
593
+ */
594
+ refreshCollection(index: string, collection: string): Promise<estypes.ShardsOperationResponseBase>;
595
+ /**
596
+ * Returns true if the document exists
597
+ *
598
+ * @param {String} index - Index name
599
+ * @param {String} collection - Collection name
600
+ * @param {String} id - Document ID
601
+ *
602
+ * @returns {Promise.<boolean>}
603
+ */
604
+ exists(index: string, collection: string, id: string): Promise<boolean>;
605
+ /**
606
+ * Returns the list of documents existing with the ids given in the body param
607
+ * NB: Due to internal Kuzzle mechanism, can only be called on a single
608
+ * index/collection, using the body { ids: [.. } syntax.
609
+ *
610
+ * @param {String} index - Index name
611
+ * @param {String} collection - Collection name
612
+ * @param {Array.<String>} ids - Document IDs
613
+ *
614
+ * @returns {Promise.<{ items: Array<{ _id, _source, _version }>, errors }>}
615
+ */
616
+ mExists(index: string, collection: string, ids: string[]): Promise<{
617
+ errors: any[];
618
+ item: any[];
619
+ items?: undefined;
620
+ } | {
621
+ errors: any[];
622
+ items: any[];
623
+ item?: undefined;
624
+ }>;
625
+ /**
626
+ * Returns true if the index exists
627
+ *
628
+ * @param {String} index - Index name
629
+ *
630
+ * @returns {Promise.<boolean>}
631
+ */
632
+ hasIndex(index: string): Promise<boolean>;
633
+ /**
634
+ * Returns true if the collection exists
635
+ *
636
+ * @param {String} index - Index name
637
+ * @param {String} collection - Collection name
638
+ *
639
+ * @returns {Promise.<boolean>}
640
+ */
641
+ hasCollection(index: string, collection: string): Promise<boolean>;
642
+ /**
643
+ * Returns true if the index has the hidden collection
644
+ *
645
+ * @param {String} index - Index name
646
+ *
647
+ * @returns {Promise.<boolean>}
648
+ */
649
+ _hasHiddenCollection(index: any): Promise<any>;
650
+ /**
651
+ * Creates multiple documents at once.
652
+ * If a content has no id, one is automatically generated and assigned to it.
653
+ * If a content has a specified identifier, it is rejected if it already exists
654
+ *
655
+ * @param {String} index - Index name
656
+ * @param {String} collection - Collection name
657
+ * @param {Object[]} documents - Documents
658
+ * @param {Object} options - timeout (undefined), refresh (undefined), userId (null)
659
+ *
660
+ * @returns {Promise.<Object>} { items, errors }
661
+ */
662
+ mCreate(index: string, collection: string, documents: JSON[], { refresh, timeout, userId, }?: {
663
+ refresh?: boolean | "wait_for";
664
+ timeout?: string;
665
+ userId?: string;
666
+ }): Promise<any>;
667
+ /**
668
+ * Creates or replaces multiple documents at once.
669
+ *
670
+ * @param {String} index - Index name
671
+ * @param {String} collection - Collection name
672
+ * @param {Object[]} documents - Documents
673
+ * @param {Object} options - timeout (undefined), refresh (undefined), userId (null), injectKuzzleMeta (false), limits (true)
674
+ *
675
+ * @returns {Promise.<{ items, errors }>
676
+ */
677
+ mCreateOrReplace(index: string, collection: string, documents: JSONObject[], { refresh, timeout, userId, injectKuzzleMeta, limits, source, }?: KRequestParams): Promise<any>;
678
+ /**
679
+ * Updates multiple documents with one request
680
+ * Replacements are rejected if targeted documents do not exist
681
+ * (like with the normal "update" method)
682
+ *
683
+ * @param {String} index - Index name
684
+ * @param {String} collection - Collection name
685
+ * @param {Object[]} documents - Documents
686
+ * @param {Object} options - timeout (undefined), refresh (undefined), retryOnConflict (0), userId (null)
687
+ *
688
+ * @returns {Promise.<Object>} { items, errors }
689
+ */
690
+ mUpdate(index: string, collection: string, documents: JSONObject[], { refresh, retryOnConflict, timeout, userId, }?: {
691
+ refresh?: any;
692
+ retryOnConflict?: number;
693
+ timeout?: any;
694
+ userId?: any;
695
+ }): Promise<any>;
696
+ /**
697
+ * Creates or replaces multiple documents at once.
698
+ *
699
+ * @param {String} index - Index name
700
+ * @param {String} collection - Collection name
701
+ * @param {Object[]} documents - Documents
702
+ * @param {Object} options - refresh (undefined), retryOnConflict (0), timeout (undefined), userId (null)
703
+ *
704
+ * @returns {Promise.<{ items, errors }>
705
+ */
706
+ mUpsert(index: string, collection: string, documents: JSONObject[], { refresh, retryOnConflict, timeout, userId, }?: {
707
+ refresh?: boolean | "wait_for";
708
+ retryOnConflict?: number;
709
+ timeout?: string;
710
+ userId?: string;
711
+ }): Promise<any>;
712
+ /**
713
+ * Replaces multiple documents at once.
714
+ * Replacements are rejected if targeted documents do not exist
715
+ * (like with the normal "replace" method)
716
+ *
717
+ * @param {String} index - Index name
718
+ * @param {String} collection - Collection name
719
+ * @param {Object[]} documents - Documents
720
+ * @param {Object} options - timeout (undefined), refresh (undefined), userId (null)
721
+ *
722
+ * @returns {Promise.<Object>} { items, errors }
723
+ */
724
+ mReplace(index: string, collection: string, documents: JSONObject[], { refresh, timeout, userId, }?: {
725
+ refresh?: boolean | "wait_for";
726
+ timeout?: string;
727
+ userId?: string;
728
+ }): Promise<any>;
729
+ /**
730
+ * Deletes multiple documents with one request
731
+ *
732
+ * @param {String} index - Index name
733
+ * @param {String} collection - Collection name
734
+ * @param {Array.<String>} ids - Documents IDs
735
+ * @param {Object} options - timeout (undefined), refresh (undefined)
736
+ *
737
+ * @returns {Promise.<{ documents, errors }>
738
+ */
739
+ mDelete(index: string, collection: string, ids: string[], { refresh, }?: {
740
+ refresh?: boolean | "wait_for";
741
+ timeout?: number;
742
+ }): Promise<{
743
+ documents: any[];
744
+ errors: any[];
745
+ }>;
746
+ /**
747
+ * Executes an ES request prepared by mcreate, mupdate, mreplace, mdelete or mwriteDocuments
748
+ * Returns a standardized ES response object, containing the list of
749
+ * successfully performed operations, and the rejected ones
750
+ *
751
+ * @param {Object} esRequest - Elasticsearch request
752
+ * @param {Object[]} documents - Document sources (format: {_id, _source})
753
+ * @param {Object[]} partialErrors - pre-rejected documents
754
+ * @param {Object} options - limits (true)
755
+ *
756
+ * @returns {Promise.<Object[]>} results
757
+ */
758
+ _mExecute(esRequest: estypes.BulkRequest, documents: JSONObject[], partialErrors?: JSONObject[], { limits, source }?: {
759
+ limits?: boolean;
760
+ source?: boolean;
761
+ }): Promise<any>;
762
+ /**
763
+ * Extracts, injects metadata and validates documents contained
764
+ * in a Request
765
+ *
766
+ * Used by mCreate, mUpdate, mUpsert, mReplace and mCreateOrReplace
767
+ *
768
+ * @param {Object[]} documents - Documents
769
+ * @param {Object} metadata - Kuzzle metadata
770
+ * @param {Object} options - prepareMGet (false), requireId (false)
771
+ *
772
+ * @returns {Object} { rejected, extractedDocuments, documentsToGet }
773
+ */
774
+ _extractMDocuments(documents: JSONObject[], metadata: JSONObject, { prepareMGet, requireId, prepareMUpsert }?: {
775
+ prepareMGet?: boolean;
776
+ requireId?: boolean;
777
+ prepareMUpsert?: boolean;
778
+ }): {
779
+ documentsToGet: any[];
780
+ extractedDocuments: any[];
781
+ rejected: any[];
782
+ };
783
+ private _hasExceededLimit;
784
+ private _processExtract;
785
+ /**
786
+ * Throws an error if the provided mapping is invalid
787
+ *
788
+ * @param {Object} mapping
789
+ * @throws
790
+ */
791
+ _checkMappings(mapping: JSONObject, path?: any[], check?: boolean): void;
792
+ /**
793
+ * Given index + collection, returns the associated alias name.
794
+ * Prefer this function to `_getIndice` and `_getAvailableIndice` whenever it is possible.
795
+ *
796
+ * @param {String} index
797
+ * @param {String} collection
798
+ *
799
+ * @returns {String} Alias name (eg: '@&nepali.liia')
800
+ */
801
+ _getAlias(index: any, collection: any): string;
802
+ /**
803
+ * Given an alias name, returns the associated index name.
804
+ */
805
+ _checkIfAliasExists(aliasName: any): Promise<boolean>;
806
+ /**
807
+ * Given index + collection, returns the associated indice name.
808
+ * Use this function if ES does not accept aliases in the request. Otherwise use `_getAlias`.
809
+ *
810
+ * @param {String} index
811
+ * @param {String} collection
812
+ *
813
+ * @returns {String} Indice name (eg: '&nepali.liia')
814
+ * @throws If there is not exactly one indice associated
815
+ */
816
+ _getIndice(index: string, collection: string): Promise<string>;
817
+ /**
818
+ * Given an ES Request returns the settings of the corresponding indice.
819
+ *
820
+ * @param esRequest the ES Request with wanted settings.
821
+ * @return {Promise<*>} the settings of the indice.
822
+ * @private
823
+ */
824
+ _getSettings(esRequest: estypes.IndicesGetSettingsRequest): Promise<any>;
825
+ /**
826
+ * Given index + collection, returns an available indice name.
827
+ * Use this function when creating the associated indice. Otherwise use `_getAlias`.
828
+ *
829
+ * @param {String} index
830
+ * @param {String} collection
831
+ *
832
+ * @returns {String} Available indice name (eg: '&nepali.liia2')
833
+ */
834
+ _getAvailableIndice(index: string, collection: string): Promise<string>;
835
+ /**
836
+ * Given an indice, returns the associated alias name.
837
+ *
838
+ * @param {String} indice
839
+ *
840
+ * @returns {String} Alias name (eg: '@&nepali.liia')
841
+ * @throws If there is not exactly one alias associated that is prefixed with @
842
+ */
843
+ _getAliasFromIndice(indice: any): Promise<string[]>;
844
+ /**
845
+ * Check for each indice whether it has an alias or not.
846
+ * When the latter is missing, create one based on the indice name.
847
+ *
848
+ * This check avoids a breaking change for those who were using Kuzzle before
849
+ * alias attribution for each indice turned into a standard (appear in 2.14.0).
850
+ */
851
+ generateMissingAliases(): Promise<void>;
852
+ /**
853
+ * Throws if index or collection includes forbidden characters
854
+ *
855
+ * @param {String} index
856
+ * @param {String} collection
857
+ */
858
+ _assertValidIndexAndCollection(index: any, collection?: any): void;
859
+ /**
860
+ * Given an alias, extract the associated index.
861
+ *
862
+ * @param {String} alias
863
+ *
864
+ * @returns {String} Index name
865
+ */
866
+ _extractIndex(alias: any): any;
867
+ /**
868
+ * Given an alias, extract the associated collection.
869
+ *
870
+ * @param {String} alias
871
+ *
872
+ * @returns {String} Collection name
873
+ */
874
+ _extractCollection(alias: any): any;
875
+ /**
876
+ * Given aliases, extract indexes and collections.
877
+ *
878
+ * @param {Array.<String>} aliases
879
+ * @param {Object.Boolean} includeHidden Only refers to `HIDDEN_COLLECTION` occurences. An empty index will still be listed. Default to `false`.
880
+ *
881
+ * @returns {Object.<String, String[]>} Indexes as key and an array of their collections as value
882
+ */
883
+ _extractSchema(aliases: string[], { includeHidden }?: {
884
+ includeHidden?: boolean;
885
+ }): {};
886
+ /**
887
+ * Creates the hidden collection on the provided index if it does not already
888
+ * exists
889
+ *
890
+ * @param {String} index Index name
891
+ */
892
+ _createHiddenCollection(index: any): Promise<void>;
893
+ /**
894
+ * We need to always wait for a minimal number of shards to be available
895
+ * before answering to the client. This is to avoid Elasticsearch node
896
+ * to return a 404 Not Found error when the client tries to index a
897
+ * document in the index.
898
+ * To find the best value for this setting, we need to take into account
899
+ * the number of nodes in the cluster and the number of shards per index.
900
+ */
901
+ _getWaitForActiveShards(): Promise<estypes.WaitForActiveShards>;
902
+ /**
903
+ * Scroll indice in elasticsearch and return all document that match the filter
904
+ * /!\ throws a write_limit_exceed error: this method is intended to be used
905
+ * by deleteByQuery and updateByQuery
906
+ *
907
+ * @param {Object} esRequest - Search request body
908
+ *
909
+ * @returns {Promise.<Array>} resolve to an array of documents
910
+ */
911
+ _getAllDocumentsFromQuery(esRequest: estypes.SearchRequest): Promise<{
912
+ _id: any;
913
+ _source: any;
914
+ body: {};
915
+ }[]>;
916
+ /**
917
+ * Clean and normalize the searchBody
918
+ * Ensure only allowed parameters are passed to ES
919
+ *
920
+ * @param {Object} searchBody - ES search body (with query, aggregations, sort, etc)
921
+ */
922
+ _sanitizeSearchBody(searchBody: any): any;
923
+ /**
924
+ * Throw if a script is used in the query.
925
+ *
926
+ * Only Stored Scripts are accepted
927
+ *
928
+ * @param {Object} object
929
+ */
930
+ _scriptCheck(object: any): void;
931
+ /**
932
+ * Checks if a collection name is valid
933
+ * @param {string} name
934
+ * @returns {Boolean}
935
+ */
936
+ isCollectionNameValid(name: any): boolean;
937
+ /**
938
+ * Checks if a collection name is valid
939
+ * @param {string} name
940
+ * @returns {Boolean}
941
+ */
942
+ isIndexNameValid(name: any): boolean;
943
+ /**
944
+ * Clears an allocated scroll
945
+ * @param {[type]} id [description]
946
+ * @returns {[type]} [description]
947
+ */
948
+ clearScroll(id?: string): Promise<void>;
949
+ /**
950
+ * Loads a configuration value from services.storageEngine and assert a valid
951
+ * ms format.
952
+ *
953
+ * @param {String} key - relative path to the key in configuration
954
+ *
955
+ * @returns {Number} milliseconds
956
+ */
957
+ _loadMsConfig(key: any): number;
958
+ /**
959
+ * Returns true if one of the mappings dynamic property changes value from
960
+ * false to true
961
+ */
962
+ _dynamicChanges(previousMappings: any, newMappings: any): boolean;
963
+ waitForElasticsearch(): Promise<void>;
964
+ /**
965
+ * Checks if the dynamic properties are correct
966
+ */
967
+ _checkDynamicProperty(mappings: any): void;
968
+ _setLastActionToKuzzleMeta(esRequest: JSONObject, alias: string, kuzzleMeta: JSONObject): void;
969
+ _setLastActionToKuzzleMetaUpdate(item: JSONObject, kuzzleMeta: JSONObject): void;
970
+ _getHitsTotalValue(hits: estypes.SearchHitsMetadata): number;
971
+ _getRandomNumber(number: number): number;
972
+ }