File tree 2 files changed +19
-1
lines changed 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,8 @@ module.exports = {
40
40
API_VERSION : process . env . ES_API_VERSION || '6.8' ,
41
41
ES_INDEX : process . env . ES_INDEX || 'challenge' ,
42
42
ES_TYPE : process . env . ES_TYPE || '_doc' , // ES 6.x accepts only 1 Type per index and it's mandatory to define it
43
- ES_REFRESH : process . env . ES_REFRESH || 'true'
43
+ ES_REFRESH : process . env . ES_REFRESH || 'true' ,
44
+ TEMP_REINDEXING : process . env . TEMP_REINDEXING || true // if true, it won't delete the existing index when reindexing data
44
45
} ,
45
46
46
47
// in bytes
Original file line number Diff line number Diff line change @@ -33,9 +33,22 @@ function createIndex (indexName) {
33
33
}
34
34
35
35
async function updateMappings ( ) {
36
+ const tempReindexing = config . get ( 'ES.TEMP_REINDEXING' )
36
37
let indexName = config . get ( 'ES.ES_INDEX' )
37
38
let newIndexName = `${ indexName } _tmp_dont_use_for_querying`
38
39
40
+ if ( tempReindexing ) {
41
+ try {
42
+ logger . info ( `Attemp to remove temporary index ${ newIndexName } ` )
43
+ await esClient . indices . delete ( {
44
+ index : newIndexName
45
+ } )
46
+ await sleep ( 500 )
47
+ } catch ( e ) {
48
+ logger . info ( `Index ${ newIndexName } does not exist` )
49
+ }
50
+ }
51
+
39
52
await createIndex ( newIndexName )
40
53
await sleep ( 500 )
41
54
logger . info ( `Reindexing from ${ indexName } to ${ newIndexName } ` )
@@ -47,6 +60,10 @@ async function updateMappings () {
47
60
waitForCompletion : true
48
61
} )
49
62
63
+ if ( tempReindexing ) {
64
+ return
65
+ }
66
+
50
67
logger . warn ( `Deleting ${ indexName } . If script crashes after this point data may be lost and a recreation of index will be required.` )
51
68
52
69
await esClient . indices . delete ( {
You can’t perform that action at this time.
0 commit comments