@@ -374,11 +374,10 @@ async function createResource (currentUser, resource) {
374
374
createdBy : currentUser . handle || currentUser . sub
375
375
} , resource ) )
376
376
377
- // Create resources in ES
378
- const esClient = await helper . getESClient ( )
379
- await esClient . create ( {
380
- index : config . ES . ES_INDEX ,
381
- type : config . ES . ES_TYPE ,
377
+ // Create resources in OS
378
+ const osClient = await helper . getOSClient ( )
379
+ await osClient . index ( {
380
+ index : config . OS . OS_INDEX ,
382
381
id : ret . id ,
383
382
body : _ . pick ( ret , payloadFields ) ,
384
383
refresh : 'true' // refresh ES so that it is visible for read operations instantly
@@ -463,13 +462,12 @@ async function deleteResource (currentUser, resource) {
463
462
464
463
await ret . delete ( )
465
464
466
- // delete from ES
467
- const esClient = await helper . getESClient ( )
468
- await esClient . delete ( {
469
- index : config . ES . ES_INDEX ,
470
- type : config . ES . ES_TYPE ,
465
+ // delete from OS
466
+ const osClient = await helper . getOSClient ( )
467
+ await osClient . delete ( {
468
+ index : config . OS . OS_INDEX ,
471
469
id : ret . id ,
472
- refresh : 'true' // refresh ES so that it is effective for read operations instantly
470
+ refresh : 'true' // refresh OS so that it is effective for read operations instantly
473
471
} )
474
472
475
473
logger . debug ( `Deleted resource, posting to Bus API: ${ JSON . stringify ( _ . pick ( ret , payloadFields ) ) } ` )
@@ -521,12 +519,12 @@ async function listChallengesByMember (memberId, criteria) {
521
519
}
522
520
523
521
if ( criteria . useScroll ) {
524
- docs = await searchESWithScroll ( mustQuery )
522
+ docs = await searchOSWithScroll ( mustQuery )
525
523
} else if ( perPage * page <= config . MAX_ELASTIC_SEARCH_RECORDS_SIZE ) {
526
- docs = await searchES ( mustQuery , perPage , page )
524
+ docs = await searchOS ( mustQuery , perPage , page )
527
525
} else {
528
526
throw new errors . BadRequestError ( `
529
- ES pagination params:
527
+ OS pagination params:
530
528
page ${ page } ,
531
529
perPage: ${ perPage }
532
530
exceeds the max search window:${ config . MAX_ELASTIC_SEARCH_RECORDS_SIZE } `
@@ -554,11 +552,10 @@ listChallengesByMember.schema = {
554
552
} ) . required ( )
555
553
}
556
554
557
- async function searchESWithScroll ( mustQuery ) {
555
+ async function searchOSWithScroll ( mustQuery ) {
558
556
const scrollTimeout = '1m'
559
- const esQuery = {
560
- index : config . get ( 'ES.ES_INDEX' ) ,
561
- type : config . get ( 'ES.ES_TYPE' ) ,
557
+ const osQuery = {
558
+ index : config . get ( 'OS.OS_INDEX' ) ,
562
559
size : 10000 ,
563
560
body : {
564
561
query : {
@@ -570,8 +567,8 @@ async function searchESWithScroll (mustQuery) {
570
567
scroll : scrollTimeout
571
568
}
572
569
573
- const esClient = await helper . getESClient ( )
574
- const searchResponse = await esClient . search ( esQuery )
570
+ const osClient = await helper . getOSClient ( )
571
+ const searchResponse = await osClient . search ( osQuery )
575
572
576
573
// eslint-disable-next-line camelcase
577
574
const { _scroll_id, hits } = searchResponse
@@ -581,7 +578,7 @@ async function searchESWithScroll (mustQuery) {
581
578
let scrollId = _scroll_id
582
579
583
580
while ( hits . hits . length < totalHits ) {
584
- const nextScrollResponse = await esClient . scroll ( {
581
+ const nextScrollResponse = await osClient . scroll ( {
585
582
scroll : scrollTimeout ,
586
583
scroll_id : scrollId
587
584
} )
@@ -590,7 +587,7 @@ async function searchESWithScroll (mustQuery) {
590
587
hits . hits = [ ...hits . hits , ...nextScrollResponse . hits . hits ]
591
588
}
592
589
593
- await esClient . clearScroll ( {
590
+ await osClient . clearScroll ( {
594
591
body : {
595
592
// eslint-disable-next-line camelcase
596
593
scroll_id : [ _scroll_id ]
@@ -606,18 +603,17 @@ async function searchESWithScroll (mustQuery) {
606
603
}
607
604
608
605
/**
609
- * Execute ES query
606
+ * Execute OS query
610
607
* @param {Object } mustQuery the query that will be sent to ES
611
608
* @param {Number } perPage number of search result per page
612
609
* @param {Number } page the current page
613
- * @returns {Object } doc from ES
610
+ * @returns {Object } doc from OS
614
611
*/
615
- async function searchES ( mustQuery , perPage , page , sortCriteria ) {
616
- let esQuery
612
+ async function searchOS ( mustQuery , perPage , page , sortCriteria ) {
613
+ let osQuery
617
614
if ( sortCriteria ) {
618
- esQuery = {
619
- index : config . get ( 'ES.ES_INDEX' ) ,
620
- type : config . get ( 'ES.ES_TYPE' ) ,
615
+ osQuery = {
616
+ index : config . get ( 'OS.OS_INDEX' ) ,
621
617
size : perPage ,
622
618
from : perPage * ( page - 1 ) , // Es Index starts from 0
623
619
body : {
@@ -630,9 +626,8 @@ async function searchES (mustQuery, perPage, page, sortCriteria) {
630
626
}
631
627
}
632
628
} else {
633
- esQuery = {
634
- index : config . get ( 'ES.ES_INDEX' ) ,
635
- type : config . get ( 'ES.ES_TYPE' ) ,
629
+ osQuery = {
630
+ index : config . get ( 'OS.OS_INDEX' ) ,
636
631
size : perPage ,
637
632
from : perPage * ( page - 1 ) , // Es Index starts from 0
638
633
body : {
@@ -644,11 +639,11 @@ async function searchES (mustQuery, perPage, page, sortCriteria) {
644
639
}
645
640
}
646
641
}
647
- logger . debug ( `ES Query ${ JSON . stringify ( esQuery ) } ` )
648
- const esClient = await helper . getESClient ( )
642
+ logger . debug ( `OS Query ${ JSON . stringify ( osQuery ) } ` )
643
+ const osClient = await helper . getOSClient ( )
649
644
let docs
650
645
try {
651
- docs = await esClient . search ( esQuery )
646
+ docs = await osClient . search ( osQuery )
652
647
} catch ( e ) {
653
648
// Catch error when the ES is fresh and has no data
654
649
logger . info ( `Query Error from ES ${ JSON . stringify ( e ) } ` )
@@ -675,9 +670,8 @@ async function getResourceCount (challengeId, roleId) {
675
670
must . push ( { term : { 'roleId.keyword' : roleId } } )
676
671
}
677
672
678
- const esQuery = {
679
- index : config . get ( 'ES.ES_INDEX' ) ,
680
- type : config . get ( 'ES.ES_TYPE' ) ,
673
+ const osQuery = {
674
+ index : config . get ( 'OS.OS_INDEX' ) ,
681
675
size : 0 ,
682
676
body : {
683
677
query : {
@@ -695,10 +689,10 @@ async function getResourceCount (challengeId, roleId) {
695
689
}
696
690
}
697
691
698
- const esClient = await helper . getESClient ( )
692
+ const osClient = await helper . getOSClient ( )
699
693
let result
700
694
try {
701
- result = await esClient . search ( esQuery )
695
+ result = await osClient . search ( osQuery )
702
696
} catch ( err ) {
703
697
logger . error ( `Get Resource Count Error ${ JSON . stringify ( err ) } ` )
704
698
throw err
0 commit comments