Skip to content

Commit f1bc9bf

Browse files
#179 - HOTFIX. Allow v5 challengeIds
1 parent dce356c commit f1bc9bf

File tree

7 files changed

+49
-4
lines changed

7 files changed

+49
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ This script will load the data from `scripts/data` directory into ES
9494
npm run start
9595
```
9696

97+
#### Duplicating the ES Index
98+
99+
To duplicate the existing ES Index (from the `ES_INDEX` to `ES_INDEX_V2` based on the configs in `config/default.js`) run `npm run create-new-index`
100+
97101
#### Linting JS files
98102

99103
```

config/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ module.exports = {
2828
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
2929
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
3030
esConfig: {
31-
HOST: process.env.ES_HOST,
31+
HOST: process.env.ES_HOST || 'localhost:9200',
3232
API_VERSION: process.env.ES_API_VERSION || '6.3',
3333
ES_INDEX: process.env.ES_INDEX || 'submission',
34+
ES_INDEX_V2: process.env.ES_INDEX_V2 || 'new_submission',
3435
ES_TYPE: process.env.ES_TYPE || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it
3536
},
3637
PAGE_SIZE: process.env.PAGE_SIZE || 20,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"create-tables": "node scripts/createTables.js",
1212
"init-db": "node scripts/importData.js",
1313
"create-index": "node scripts/createIndex.js",
14+
"create-new-index": "node scripts/createNewIndex.js",
1415
"delete-index": "node scripts/deleteIndex.js",
1516
"init-es": "node scripts/loadES.js",
1617
"db-to-es": "node scripts/migrateFromDBToES.js",

scripts/createNewIndex.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copies the existing index to a new index and updates the type of challengeId
3+
* to be keyword (It is long in the source index)
4+
*/
5+
6+
const co = require('co')
7+
const config = require('config')
8+
const logger = require('../src/common/logger')
9+
const helper = require('../src/common/helper')
10+
11+
co(function * createIndex () {
12+
logger.info('ES Index creation started!')
13+
const esClient = helper.getEsClient()
14+
const indices = yield esClient.indices.get({
15+
index: config.get('esConfig.ES_INDEX')
16+
})
17+
const existingIndex = indices[config.get('esConfig.ES_INDEX')]
18+
const existingMappings = existingIndex.mappings[config.get('esConfig.ES_TYPE')]
19+
const body = { mappings: {} }
20+
body.mappings[config.get('esConfig.ES_TYPE')] = {
21+
properties: {
22+
...existingMappings.properties,
23+
challengeId: { type: 'keyword' },
24+
memberId: { type: 'keyword' }
25+
}
26+
}
27+
yield esClient.indices.create({
28+
index: config.get('esConfig.ES_INDEX_V2'),
29+
body
30+
})
31+
logger.info('ES Index creation succeeded!')
32+
process.exit(0)
33+
}).catch((err) => {
34+
logger.logFullError(err)
35+
process.exit(1)
36+
})

scripts/deleteIndex.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ const helper = require('../src/common/helper')
1010
co(function * deleteIndex () {
1111
logger.info('ES Index deletion started!')
1212
const esClient = helper.getEsClient()
13+
// yield esClient.indices.delete({
14+
// index: config.get('esConfig.ES_INDEX')
15+
// })
1316
yield esClient.indices.delete({
14-
index: config.get('esConfig.ES_INDEX')
17+
index: config.get('esConfig.ES_INDEX_V2')
1518
})
1619
logger.info('ES Index deletion succeeded!')
1720
process.exit(0)

scripts/migrateFromDBToES.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function * migrateRecords (tableName) {
2929
logger.debug(`Number of ${tableName}s fetched from DB - ` + totalRecords)
3030
for (let i = 0; i < totalRecords; i++) {
3131
const record = {
32-
index: config.get('esConfig.ES_INDEX'),
32+
index: config.get('esConfig.ES_INDEX_V2'),
3333
type: config.get('esConfig.ES_TYPE'),
3434
id: records.Items[i].id,
3535
body: {

src/common/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function prepESFilter (query, actResource) {
176176
}
177177

178178
const searchCriteria = {
179-
index: config.get('esConfig.ES_INDEX'),
179+
index: config.get('esConfig.ES_INDEX_V2'),
180180
type: config.get('esConfig.ES_TYPE'),
181181
size: pageSize,
182182
from: (page - 1) * pageSize, // Es Index starts from 0

0 commit comments

Comments
 (0)