@cumulus/es-client 10.1.2 → 11.1.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.
package/indexer.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* functions for transforming and indexing Cumulus Payloads
2
- * in ElasticSearch. These functions are specifically designed
2
+ * in Elasticsearch. These functions are specifically designed
3
3
  * to transform data for use in cumulus api
4
4
  *
5
5
  * The module accepts the following kinds of workflows (state machines):
@@ -46,9 +46,9 @@ async function createIndex(esClient, indexName) {
46
46
  }
47
47
 
48
48
  /**
49
- * Indexes a given record to the specified ElasticSearch index and type
49
+ * Indexes a given record to the specified Elasticsearch index and type
50
50
  *
51
- * @param {Object} esClient - ElasticSearch Connection object
51
+ * @param {Object} esClient - Elasticsearch Connection object
52
52
  * @param {string} id - the record id
53
53
  * @param {Object} doc - the record
54
54
  * @param {string} index - Elasticsearch index alias
@@ -84,11 +84,99 @@ async function genericRecordUpdate(esClient, id, doc, index, type, parent) {
84
84
  return indexResponse.body;
85
85
  }
86
86
 
87
+ /**
88
+ * Updates a given record for the Elasticsearch index and type
89
+ *
90
+ * @param {Object} esClient - Elasticsearch Connection object
91
+ * @param {string} id - the record id
92
+ * @param {Object} doc - the record
93
+ * @param {string} index - Elasticsearch index alias
94
+ * @param {string} type - Elasticsearch type
95
+ * @returns {Promise} Elasticsearch response
96
+ */
97
+ async function updateExistingRecord(esClient, id, doc, index, type) {
98
+ return await esClient.update({
99
+ index,
100
+ type,
101
+ id,
102
+ body: {
103
+ doc: {
104
+ ...doc,
105
+ timestamp: Date.now(),
106
+ },
107
+ },
108
+ refresh: inTestMode(),
109
+ });
110
+ }
111
+
112
+ /**
113
+ * Updates an asyncOperation record in Elasticsearch
114
+ *
115
+ * @param {Object} esClient - Elasticsearch Connection object
116
+ * @param {Object} id - Record ID
117
+ * @param {Object} updates - Document of updates to apply
118
+ * @param {string} index - Elasticsearch index alias (default defined in search.js)
119
+ * @param {string} type - Elasticsearch type (default: asyncOperation)
120
+ * @returns {Promise} elasticsearch update response
121
+ */
122
+ function updateAsyncOperation(esClient, id, updates, index = defaultIndexAlias, type = 'asyncOperation') {
123
+ return updateExistingRecord(esClient, id, updates, index, type);
124
+ }
125
+
126
+ /**
127
+ * Upsert an execution record in Elasticsearch
128
+ *
129
+ * @param {Object} params
130
+ * @param {Object} params.esClient - Elasticsearch Connection object
131
+ * @param {Object} params.updates - Document of updates to apply
132
+ * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
133
+ * @param {string} params.type - Elasticsearch type (default: execution)
134
+ * @param {string} [params.refresh] - whether to refresh the index on update or not
135
+ * @returns {Promise} elasticsearch update response
136
+ */
137
+ async function upsertExecution({
138
+ esClient,
139
+ updates,
140
+ index = defaultIndexAlias,
141
+ type = 'execution',
142
+ refresh,
143
+ }) {
144
+ const upsertDoc = {
145
+ ...updates,
146
+ timestamp: Date.now(),
147
+ };
148
+ return await esClient.update({
149
+ index,
150
+ type,
151
+ id: upsertDoc.arn,
152
+ body: {
153
+ script: {
154
+ lang: 'painless',
155
+ inline: `
156
+ if (params.doc.status == "running") {
157
+ ctx._source.updatedAt = params.doc.updatedAt;
158
+ ctx._source.timestamp = params.doc.timestamp;
159
+ ctx._source.originalPayload = params.doc.originalPayload;
160
+ } else {
161
+ ctx._source.putAll(params.doc)
162
+ }
163
+ `,
164
+ params: {
165
+ doc: upsertDoc,
166
+ },
167
+ },
168
+ upsert: upsertDoc,
169
+ },
170
+ refresh: refresh !== undefined ? refresh : inTestMode(),
171
+ retry_on_conflict: 3,
172
+ });
173
+ }
174
+
87
175
  /**
88
176
  * Indexes a step function message to Elastic Search. The message must
89
177
  * comply with the cumulus message protocol
90
178
  *
91
- * @param {Object} esClient - ElasticSearch Connection object
179
+ * @param {Object} esClient - Elasticsearch Connection object
92
180
  * @param {Object} payload - Cumulus Step Function message
93
181
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
94
182
  * @param {string} type - Elasticsearch type (default: execution)
@@ -99,9 +187,9 @@ function indexExecution(esClient, payload, index = defaultIndexAlias, type = 'ex
99
187
  }
100
188
 
101
189
  /**
102
- * Indexes the asyncOperation type on ElasticSearch
190
+ * Indexes the asyncOperation type on Elasticsearch
103
191
  *
104
- * @param {Object} esClient - ElasticSearch Connection object
192
+ * @param {Object} esClient - Elasticsearch Connection object
105
193
  * @param {Object} payload - Cumulus Step Function message
106
194
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
107
195
  * @param {string} type - Elasticsearch type (default: asyncOperation)
@@ -112,23 +200,23 @@ function indexAsyncOperation(esClient, payload, index = defaultIndexAlias, type
112
200
  }
113
201
 
114
202
  /**
115
- * Indexes the collection on ElasticSearch
203
+ * Indexes the collection on Elasticsearch
116
204
  *
117
- * @param {Object} esClient - ElasticSearch Connection object
118
- * @param {Object} meta - the collection record
119
- * @param {string} index - Elasticsearch index alias (default defined in search.js)
120
- * @param {string} type - Elasticsearch type (default: collection)
205
+ * @param {Object} esClient - Elasticsearch Connection object
206
+ * @param {Object} collection - the collection record
207
+ * @param {string} index - Elasticsearch index alias (default defined in search.js)
208
+ * @param {string} type - Elasticsearch type (default: collection)
121
209
  * @returns {Promise} Elasticsearch response
122
210
  */
123
- function indexCollection(esClient, meta, index = defaultIndexAlias, type = 'collection') {
124
- const collectionId = constructCollectionId(meta.name, meta.version);
125
- return genericRecordUpdate(esClient, collectionId, meta, index, type);
211
+ function indexCollection(esClient, collection, index = defaultIndexAlias, type = 'collection') {
212
+ const collectionId = constructCollectionId(collection.name, collection.version);
213
+ return genericRecordUpdate(esClient, collectionId, collection, index, type);
126
214
  }
127
215
 
128
216
  /**
129
- * Indexes the provider type on ElasticSearch
217
+ * Indexes the provider type on Elasticsearch
130
218
  *
131
- * @param {Object} esClient - ElasticSearch Connection object
219
+ * @param {Object} esClient - Elasticsearch Connection object
132
220
  * @param {Object} payload - the provider record
133
221
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
134
222
  * @param {string} type - Elasticsearch type (default: provider)
@@ -139,9 +227,9 @@ function indexProvider(esClient, payload, index = defaultIndexAlias, type = 'pro
139
227
  }
140
228
 
141
229
  /**
142
- * Indexes the reconciliationReport type on ElasticSearch
230
+ * Indexes the reconciliationReport type on Elasticsearch
143
231
  *
144
- * @param {Object} esClient - ElasticSearch Connection object
232
+ * @param {Object} esClient - Elasticsearch Connection object
145
233
  * @param {Object} payload - the ReconciliationReport record
146
234
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
147
235
  * @param {string} type - Elasticsearch type (default: reconciliationReport)
@@ -152,9 +240,9 @@ function indexReconciliationReport(esClient, payload, index = defaultIndexAlias,
152
240
  }
153
241
 
154
242
  /**
155
- * Indexes the rule type on ElasticSearch
243
+ * Indexes the rule type on Elasticsearch
156
244
  *
157
- * @param {Object} esClient - ElasticSearch Connection object
245
+ * @param {Object} esClient - Elasticsearch Connection object
158
246
  * @param {Object} payload - the Rule record
159
247
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
160
248
  * @param {string} type - Elasticsearch type (default: rule)
@@ -166,9 +254,9 @@ function indexRule(esClient, payload, index = defaultIndexAlias, type = 'rule')
166
254
  }
167
255
 
168
256
  /**
169
- * Indexes the granule type on ElasticSearch
257
+ * Indexes the granule type on Elasticsearch
170
258
  *
171
- * @param {Object} esClient - ElasticSearch Connection object
259
+ * @param {Object} esClient - Elasticsearch Connection object
172
260
  * @param {Object} payload - Cumulus Step Function message
173
261
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
174
262
  * @param {string} type - Elasticsearch type (default: granule)
@@ -197,9 +285,67 @@ async function indexGranule(esClient, payload, index = defaultIndexAlias, type =
197
285
  }
198
286
 
199
287
  /**
200
- * Indexes the pdr type on ElasticSearch
288
+ * Upserts a granule in Elasticsearch
289
+ *
290
+ * @param {Object} params
291
+ * @param {Object} params.esClient - Elasticsearch Connection object
292
+ * @param {Object} params.updates - Updates to make
293
+ * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
294
+ * @param {string} params.type - Elasticsearch type (default: granule)
295
+ * @param {string} [params.refresh] - whether to refresh the index on update or not
296
+ * @returns {Promise} Elasticsearch response
297
+ */
298
+ async function upsertGranule({
299
+ esClient,
300
+ updates,
301
+ index = defaultIndexAlias,
302
+ type = 'granule',
303
+ refresh,
304
+ }) {
305
+ // If the granule exists in 'deletedgranule', delete it first before inserting the granule
306
+ // into ES. Ignore 404 error, so the deletion still succeeds if the record doesn't exist.
307
+ const delGranParams = {
308
+ index,
309
+ type: 'deletedgranule',
310
+ id: updates.granuleId,
311
+ parent: updates.collectionId,
312
+ refresh: inTestMode(),
313
+ };
314
+ await esClient.delete(delGranParams, { ignore: [404] });
315
+
316
+ const upsertDoc = updates;
317
+
318
+ return await esClient.update({
319
+ index,
320
+ type,
321
+ id: updates.granuleId,
322
+ parent: updates.collectionId,
323
+ body: {
324
+ script: {
325
+ lang: 'painless',
326
+ inline: `
327
+ if ((ctx._source.createdAt === null || params.doc.createdAt >= ctx._source.createdAt)
328
+ && (params.doc.status != 'running' || (params.doc.status == 'running' && params.doc.execution != ctx._source.execution))) {
329
+ ctx._source.putAll(params.doc);
330
+ } else {
331
+ ctx.op = 'none';
332
+ }
333
+ `,
334
+ params: {
335
+ doc: upsertDoc,
336
+ },
337
+ },
338
+ upsert: upsertDoc,
339
+ },
340
+ refresh: refresh !== undefined ? refresh : inTestMode(),
341
+ retry_on_conflict: 3,
342
+ });
343
+ }
344
+
345
+ /**
346
+ * Indexes the pdr type on Elasticsearch
201
347
  *
202
- * @param {Object} esClient - ElasticSearch Connection object
348
+ * @param {Object} esClient - Elasticsearch Connection object
203
349
  * @param {Object} payload - Cumulus Step Function message
204
350
  * @param {string} index - Elasticsearch index alias (default defined in search.js)
205
351
  * @param {string} type - Elasticsearch type (default: pdr)
@@ -216,10 +362,58 @@ async function indexPdr(esClient, payload, index = defaultIndexAlias, type = 'pd
216
362
  }
217
363
 
218
364
  /**
219
- * delete a record from ElasticSearch
365
+ * Upsert a PDR record in Elasticsearch
366
+ *
367
+ * @param {Object} params
368
+ * @param {Object} params.esClient - Elasticsearch Connection object
369
+ * @param {Object} params.updates - Document to upsert
370
+ * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
371
+ * @param {string} params.type - Elasticsearch type (default: execution)
372
+ * @param {string} [params.refresh] - whether to refresh the index on update or not
373
+ * @returns {Promise} elasticsearch update response
374
+ */
375
+ async function upsertPdr({
376
+ esClient,
377
+ updates,
378
+ index = defaultIndexAlias,
379
+ type = 'pdr',
380
+ refresh,
381
+ }) {
382
+ const upsertDoc = {
383
+ ...updates,
384
+ timestamp: Date.now(),
385
+ };
386
+ return await esClient.update({
387
+ index,
388
+ type,
389
+ id: upsertDoc.pdrName,
390
+ body: {
391
+ script: {
392
+ lang: 'painless',
393
+ inline: `
394
+ if ((ctx._source.createdAt === null || params.doc.createdAt >= ctx._source.createdAt)
395
+ && (params.doc.execution != ctx._source.execution || params.doc.progress > ctx._source.progress)) {
396
+ ctx._source.putAll(params.doc);
397
+ } else {
398
+ ctx.op = 'none';
399
+ }
400
+ `,
401
+ params: {
402
+ doc: upsertDoc,
403
+ },
404
+ },
405
+ upsert: upsertDoc,
406
+ },
407
+ refresh: refresh !== undefined ? refresh : inTestMode(),
408
+ retry_on_conflict: 3,
409
+ });
410
+ }
411
+
412
+ /**
413
+ * delete a record from Elasticsearch
220
414
  *
221
415
  * @param {Object} params
222
- * @param {Object} params.esClient - ElasticSearch Connection object
416
+ * @param {Object} params.esClient - Elasticsearch Connection object
223
417
  * @param {string} params.id - id of the Elasticsearch record
224
418
  * @param {string} params.type - Elasticsearch type (default: execution)
225
419
  * @param {strint} params.parent - id of the parent (optional)
@@ -248,50 +442,271 @@ async function deleteRecord({
248
442
  if (ignore) options = { ignore };
249
443
 
250
444
  const actualEsClient = esClient || (await Search.es());
251
-
252
- const getResponse = await actualEsClient.get(params, options);
253
445
  const deleteResponse = await actualEsClient.delete(params, options);
254
-
255
- if (type === 'granule' && getResponse.body.found) {
256
- const doc = getResponse.body._source;
257
- doc.timestamp = Date.now();
258
- doc.deletedAt = Date.now();
259
-
260
- // When a 'granule' record is deleted, the record is added to 'deletedgranule' type
261
- await genericRecordUpdate(
262
- actualEsClient,
263
- doc.granuleId,
264
- doc,
265
- index,
266
- 'deletedgranule',
267
- parent
268
- );
269
- }
270
446
  return deleteResponse.body;
271
447
  }
272
448
 
273
449
  /**
274
- * Index a record to local Elasticsearch. Used when running API locally.
450
+ * Deletes the collection in Elasticsearch
451
+ *
452
+ * @param {Object} params
453
+ * @param {Object} params.esClient - Elasticsearch Connection object
454
+ * @param {string} params.collectionId - the collection ID
455
+ * @param {string[]} [params.ignore] - Array of response codes to ignore
456
+ * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
457
+ * @param {string} params.type - Elasticsearch type (default: collection)
458
+ * @returns {Promise} Elasticsearch response
459
+ */
460
+ function deleteCollection({
461
+ esClient,
462
+ collectionId,
463
+ ignore,
464
+ index = defaultIndexAlias,
465
+ type = 'collection',
466
+ }) {
467
+ return deleteRecord({
468
+ esClient,
469
+ id: collectionId,
470
+ index,
471
+ type,
472
+ ignore,
473
+ });
474
+ }
475
+
476
+ /**
477
+ * Deletes the provider in Elasticsearch
275
478
  *
276
- * @param {Object} record - Record object
277
- * @param {function} doIndex - Function to do indexing operation
278
- * @returns {Promise} - Promise of indexing operation
479
+ * @param {Object} params
480
+ * @param {Object} params.esClient - Elasticsearch Connection object
481
+ * @param {string} params.id - the provider ID
482
+ * @param {string[]} [params.ignore] - Array of response codes to ignore
483
+ * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
484
+ * @param {string} params.type - Elasticsearch type (default: provider)
485
+ * @returns {Promise} Elasticsearch response
279
486
  */
280
- async function addToLocalES(record, doIndex) {
281
- const esClient = await Search.es(process.env.ES_HOST);
282
- return doIndex(esClient, record, process.env.ES_INDEX);
487
+ function deleteProvider({
488
+ esClient,
489
+ id,
490
+ ignore,
491
+ index = defaultIndexAlias,
492
+ type = 'provider',
493
+ }) {
494
+ return deleteRecord({
495
+ esClient,
496
+ id,
497
+ index,
498
+ type,
499
+ ignore,
500
+ });
501
+ }
502
+
503
+ /**
504
+ * Deletes the rule in Elasticsearch
505
+ *
506
+ * @param {Object} params
507
+ * @param {Object} params.esClient - Elasticsearch Connection object
508
+ * @param {string} params.name - the rule name
509
+ * @param {string[]} [params.ignore] - Array of response codes to ignore
510
+ * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
511
+ * @param {string} params.type - Elasticsearch type (default: rule)
512
+ * @returns {Promise} Elasticsearch response
513
+ */
514
+ function deleteRule({
515
+ esClient,
516
+ name,
517
+ ignore,
518
+ index = defaultIndexAlias,
519
+ type = 'rule',
520
+ }) {
521
+ return deleteRecord({
522
+ esClient,
523
+ id: name,
524
+ index,
525
+ type,
526
+ ignore,
527
+ });
528
+ }
529
+
530
+ /**
531
+ * Deletes the PDR in Elasticsearch
532
+ *
533
+ * @param {Object} params
534
+ * @param {Object} params.esClient - Elasticsearch Connection object
535
+ * @param {string} params.name - the PDR name
536
+ * @param {string[]} [params.ignore] - Array of response codes to ignore
537
+ * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
538
+ * @param {string} params.type - Elasticsearch type (default: PDR)
539
+ * @returns {Promise} Elasticsearch response
540
+ */
541
+ function deletePdr({
542
+ esClient,
543
+ name,
544
+ ignore,
545
+ index = defaultIndexAlias,
546
+ type = 'pdr',
547
+ }) {
548
+ return deleteRecord({
549
+ esClient,
550
+ id: name,
551
+ index,
552
+ type,
553
+ ignore,
554
+ });
555
+ }
556
+
557
+ /**
558
+ * Deletes the execution in Elasticsearch
559
+ *
560
+ * @param {Object} params
561
+ * @param {Object} params.esClient - Elasticsearch Connection object
562
+ * @param {string} params.arn - execution ARN
563
+ * @param {string[]} [params.ignore] - Array of response codes to ignore
564
+ * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
565
+ * @param {string} params.type - Elasticsearch type (default: execution)
566
+ * @returns {Promise} Elasticsearch response
567
+ */
568
+ function deleteExecution({
569
+ esClient,
570
+ arn,
571
+ ignore,
572
+ index = defaultIndexAlias,
573
+ type = 'execution',
574
+ }) {
575
+ return deleteRecord({
576
+ esClient,
577
+ id: arn,
578
+ index,
579
+ type,
580
+ ignore,
581
+ });
582
+ }
583
+
584
+ /**
585
+ * Deletes the async operation in Elasticsearch
586
+ *
587
+ * @param {Object} params
588
+ * @param {Object} params.esClient - Elasticsearch Connection object
589
+ * @param {string} params.id - the async operation ID
590
+ * @param {string[]} [params.ignore] - Array of response codes to ignore
591
+ * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
592
+ * @param {string} params.type - Elasticsearch type (default: asyncOperation)
593
+ * @returns {Promise} Elasticsearch response
594
+ */
595
+ function deleteAsyncOperation({
596
+ esClient,
597
+ id,
598
+ ignore,
599
+ index = defaultIndexAlias,
600
+ type = 'asyncOperation',
601
+ }) {
602
+ return deleteRecord({
603
+ esClient,
604
+ id,
605
+ index,
606
+ type,
607
+ ignore,
608
+ });
609
+ }
610
+
611
+ /**
612
+ * Deletes the reconciliation report from Elasticsearch
613
+ *
614
+ * @param {Object} params
615
+ * @param {Object} params.esClient - Elasticsearch Connection object
616
+ * @param {string} params.name - reconciliation report name
617
+ * @param {string[]} [params.ignore] - Array of response codes to ignore
618
+ * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
619
+ * @param {string} params.type - Elasticsearch type (default: reconciliationReport)
620
+ * @returns {Promise} Elasticsearch response
621
+ */
622
+ function deleteReconciliationReport({
623
+ esClient,
624
+ name,
625
+ ignore,
626
+ index = defaultIndexAlias,
627
+ type = 'reconciliationReport',
628
+ }) {
629
+ return deleteRecord({
630
+ esClient,
631
+ id: name,
632
+ index,
633
+ type,
634
+ ignore,
635
+ });
636
+ }
637
+
638
+ /**
639
+ * Deletes the granule in Elasticsearch
640
+ *
641
+ * @param {Object} params
642
+ * @param {Object} params.esClient - Elasticsearch Connection object
643
+ * @param {string} params.granuleId - the granule ID
644
+ * @param {string} params.collectionId - the collection ID
645
+ * @param {string[]} [params.ignore] - Array of response codes to ignore
646
+ * @param {string} params.index - Elasticsearch index alias (default defined in search.js)
647
+ * @param {string} params.type - Elasticsearch type (default: granule)
648
+ * @returns {Promise} Elasticsearch response
649
+ */
650
+ async function deleteGranule({
651
+ esClient,
652
+ granuleId,
653
+ collectionId,
654
+ ignore,
655
+ index = defaultIndexAlias,
656
+ type = 'granule',
657
+ }) {
658
+ const esGranulesClient = new Search(
659
+ {},
660
+ type,
661
+ index
662
+ );
663
+ const granuleEsRecord = await esGranulesClient.get(granuleId, collectionId);
664
+
665
+ // When a 'granule' record is deleted, the record is added to 'deletedgranule' type
666
+ const deletedGranuleDoc = granuleEsRecord;
667
+ delete deletedGranuleDoc._id;
668
+ deletedGranuleDoc.timestamp = Date.now();
669
+ deletedGranuleDoc.deletedAt = Date.now();
670
+ await genericRecordUpdate(
671
+ esClient,
672
+ granuleId,
673
+ deletedGranuleDoc,
674
+ index,
675
+ 'deletedgranule',
676
+ collectionId
677
+ );
678
+
679
+ return await deleteRecord({
680
+ esClient,
681
+ id: granuleId,
682
+ parent: collectionId,
683
+ index,
684
+ type,
685
+ ignore,
686
+ });
283
687
  }
284
688
 
285
689
  module.exports = {
286
- addToLocalES,
287
690
  createIndex,
288
691
  indexCollection,
289
692
  indexProvider,
290
693
  indexReconciliationReport,
291
694
  indexRule,
292
695
  indexGranule,
696
+ upsertGranule,
293
697
  indexPdr,
698
+ upsertPdr,
294
699
  indexExecution,
295
700
  indexAsyncOperation,
296
701
  deleteRecord,
702
+ deleteAsyncOperation,
703
+ updateAsyncOperation,
704
+ upsertExecution,
705
+ deleteCollection,
706
+ deleteProvider,
707
+ deleteRule,
708
+ deletePdr,
709
+ deleteGranule,
710
+ deleteExecution,
711
+ deleteReconciliationReport,
297
712
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cumulus/es-client",
3
- "version": "10.1.2",
3
+ "version": "11.1.1",
4
4
  "description": "Utilities for working with Elasticsearch",
5
5
  "keywords": [
6
6
  "CUMULUS",
@@ -30,21 +30,21 @@
30
30
  "author": "Cumulus Authors",
31
31
  "license": "Apache-2.0",
32
32
  "dependencies": {
33
- "@cumulus/common": "10.1.2",
34
- "@cumulus/errors": "10.1.2",
35
- "@cumulus/logger": "10.1.2",
36
- "@cumulus/message": "10.1.2",
33
+ "@cumulus/common": "11.1.1",
34
+ "@cumulus/errors": "11.1.1",
35
+ "@cumulus/logger": "11.1.1",
36
+ "@cumulus/message": "11.1.1",
37
37
  "@elastic/elasticsearch": "^5.6.20",
38
38
  "aws-elasticsearch-connector": "8.2.0",
39
39
  "aws-sdk": "^2.585.0",
40
40
  "lodash": "~4.17.21",
41
- "moment": "2.29.1",
41
+ "moment": "2.29.2",
42
42
  "p-limit": "^1.2.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@cumulus/aws-client": "10.1.2",
46
- "@cumulus/test-data": "10.1.2",
45
+ "@cumulus/aws-client": "11.1.1",
46
+ "@cumulus/test-data": "11.1.1",
47
47
  "p-each-series": "^2.1.0"
48
48
  },
49
- "gitHead": "3b59753fa85064549b70ad8ed4a4ee213c5af313"
49
+ "gitHead": "07fe682da23821434372759fb1948b081da429b5"
50
50
  }
package/search.js CHANGED
@@ -197,15 +197,30 @@ class BaseSearch {
197
197
  };
198
198
  }
199
199
 
200
- async get(id) {
200
+ async get(id, parentId) {
201
201
  const body = {
202
202
  query: {
203
- term: {
204
- _id: id,
203
+ bool: {
204
+ must: [{
205
+ term: {
206
+ _id: id,
207
+ },
208
+ }],
205
209
  },
206
210
  },
207
211
  };
208
212
 
213
+ if (parentId) {
214
+ body.query.bool.must.push(
215
+ {
216
+ parent_id: {
217
+ id: parentId,
218
+ type: this.type,
219
+ },
220
+ }
221
+ );
222
+ }
223
+
209
224
  logDetails.granuleId = id;
210
225
 
211
226
  if (!this.client) {
@@ -215,7 +230,7 @@ class BaseSearch {
215
230
  const result = await this.client.search({
216
231
  index: this.index,
217
232
  type: this.type,
218
- body: body,
233
+ body,
219
234
  }).then((response) => response.body);
220
235
 
221
236
  if (result.hits.total > 1) {
@@ -230,6 +245,11 @@ class BaseSearch {
230
245
  return resp;
231
246
  }
232
247
 
248
+ async exists(id, parentId) {
249
+ const response = await this.get(id, parentId);
250
+ return response.detail !== 'Record not found';
251
+ }
252
+
233
253
  async granulesStats(key, value) {
234
254
  const body = {
235
255
  query: {
package/testUtils.js CHANGED
@@ -1,13 +1,14 @@
1
1
  const { randomString } = require('@cumulus/common/test-utils');
2
2
 
3
- const { bootstrapElasticSearch } = require('./bootstrap');
3
+ const bootstrap = require('./bootstrap');
4
+
4
5
  const { Search } = require('./search');
5
6
 
6
7
  const createTestIndex = async () => {
7
8
  const esIndex = randomString();
8
9
  const esAlias = randomString();
9
10
  process.env.ES_INDEX = esIndex;
10
- await bootstrapElasticSearch('fakehost', esIndex, esAlias);
11
+ await bootstrap.bootstrapElasticSearch('fakehost', esIndex, esAlias);
11
12
  const esClient = await Search.es('fakehost');
12
13
  return { esIndex, esClient };
13
14
  };