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