kuzzle 2.60.1 → 2.61.0-beta.2

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