@@ -343,7 +343,7 @@ async function getChallengeIDsFromV4 (filter, perPage, page = 1) {
343
343
* @param {Number } page
344
344
* @returns {Object } { total, ids }
345
345
*/
346
- async function getChallengeIDsFromV5 ( filter , perPage , page = 1 ) {
346
+ async function getChallengeIDsFromV5 ( filter , perPage , lastDate ) {
347
347
// logger.warn(`getChallengeIDsFromV5 ${JSON.stringify(filter)} perPage ${perPage} page ${page}`)
348
348
const boolQuery = [ ]
349
349
const mustQuery = [ ]
@@ -373,7 +373,6 @@ async function getChallengeIDsFromV5 (filter, perPage, page = 1) {
373
373
type : config . get ( 'ES.CHALLENGE_ES_TYPE' ) ,
374
374
// refresh: config.get('ES.ES_REFRESH'),
375
375
size : perPage ,
376
- from : perPage * ( page - 1 ) ,
377
376
body : {
378
377
_source : [ 'legacyId' , 'id' ] ,
379
378
version : 'true' ,
@@ -390,6 +389,9 @@ async function getChallengeIDsFromV5 (filter, perPage, page = 1) {
390
389
]
391
390
}
392
391
}
392
+ if ( lastDate ) {
393
+ esQuery . body . search_after = [ Number ( lastDate ) ]
394
+ }
393
395
// Search with constructed query
394
396
let docs
395
397
// logger.warn(`V5 Challenge IDs Query ${JSON.stringify(esQuery)}`)
@@ -407,14 +409,30 @@ async function getChallengeIDsFromV5 (filter, perPage, page = 1) {
407
409
}
408
410
// logger.warn(JSON.stringify(docs))
409
411
// Extract data from hits
410
- if ( docs . hits . total > 0 ) {
412
+ let result = _ . map ( docs . hits . hits , item => item . _source )
413
+ logger . info ( `ES Search Hits Total -> ${ docs . hits . total } ` )
414
+ let newLastDate = null
415
+ if ( result . length > 0 ) {
416
+ logger . info ( `ES Search Result Length -> ${ result . length } ` )
417
+ const endSortDate = docs . hits . hits [ result . length - 1 ] . sort
418
+ if ( endSortDate && endSortDate . length ) {
419
+ logger . info ( `LastSortDate: ${ JSON . stringify ( endSortDate ) } ` )
420
+ newLastDate = endSortDate [ 0 ]
421
+ }
422
+ logger . info ( `newLastDate Timestamp: ${ newLastDate } ` )
411
423
return {
412
424
total : docs . hits . total ,
413
425
ids : _ . map ( docs . hits . hits , hit => _ . toNumber ( hit . _source . legacyId ) ) ,
414
- v5Ids : _ . map ( docs . hits . hits , hit => hit . _source . id )
426
+ v5Ids : _ . map ( docs . hits . hits , hit => hit . _source . id ) ,
427
+ lastDate : newLastDate
415
428
}
416
429
}
417
- return false
430
+ return {
431
+ total : docs . hits . total ,
432
+ ids : [ ] ,
433
+ v5Ids : [ ] ,
434
+ lastDate : newLastDate
435
+ }
418
436
}
419
437
420
438
async function getChallengeListingFromV4ES ( legacyId ) {
0 commit comments