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