Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 057d492

Browse files
committedJun 11, 2020
Update helper script to account for nested data types
1 parent 8a86454 commit 057d492

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed
 

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The following parameters can be set in config files or in env variables:
2525
- UBAHN_DELETE_TOPIC: the delete ubahn entity Kafka message topic, default value is 'u-bahn.action.delete'
2626
- ES.HOST: Elasticsearch host, default value is 'localhost:9200'
2727
- ES.AWS_REGION: The Amazon region to use when using AWS Elasticsearch service, default value is 'us-east-1'
28-
- ES.API_VERSION: Elasticsearch API version, default value is '6.8'
28+
- ES.API_VERSION: Elasticsearch API version, default value is '7.4'
2929
- ES.ACHIEVEMENT_PROVIDER_INDEX: Elasticsearch index name for achievement provider, default value is 'achievement_provider'
3030
- ES.ACHIEVEMENT_PROVIDER_TYPE: Elasticsearch index type for achievement provider, default value is '_doc'
3131
- ES.ATTRIBUTE_INDEX: Elasticsearch index name for attribute, default value is 'attribute'

‎config/default.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
ES: {
2222
HOST: process.env.ES_HOST || 'localhost:9200',
2323
AWS_REGION: process.env.AWS_REGION || 'us-east-1', // AWS Region to be used if we use AWS ES
24-
API_VERSION: process.env.ES_API_VERSION || '6.8',
24+
API_VERSION: process.env.ES_API_VERSION || '7.4',
2525
ACHIEVEMENT_PROVIDER_INDEX: process.env.ACHIEVEMENT_PROVIDER_INDEX || 'achievement_provider',
2626
ACHIEVEMENT_PROVIDER_TYPE: process.env.ACHIEVEMENT_PROVIDER_TYPE || '_doc',
2727
ATTRIBUTE_INDEX: process.env.ATTRIBUTE_INDEX || 'attribute',

‎src/common/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ const userResources = {
5555
userattribute: {
5656
propertyName: config.get('ES.USER_ATTRIBUTE_PROPERTY_NAME'),
5757
relateKey: 'attributeId',
58-
validate: payload => validProperties(payload, ['userId', 'attributeId'])
58+
validate: payload => validProperties(payload, ['userId', 'attributeId']),
59+
isNested: true // For ES index creation
5960
},
6061
userrole: {
6162
propertyName: config.get('ES.USER_ROLE_PROPERTY_NAME'),

‎test/common/init-es.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
const logger = require('../../src/common/logger')
1111
const helper = require('../../src/common/helper')
12-
const { topResources } = require('../../src/common/constants')
12+
const { topResources, userResources } = require('../../src/common/constants')
1313

1414
let client
1515

16+
let needsNestedTypes = ['user']
17+
1618
/**
1719
* Initialize elastic search index
1820
* @param {Boolean} isForce boolean flag indicate it is forced operation
@@ -31,6 +33,25 @@ const init = async (isForce) => {
3133
} else {
3234
logger.info(`The index ${topResources[key].index} will be created.`)
3335
await client.indices.create({ index: topResources[key].index })
36+
37+
if (needsNestedTypes.includes(topResources[key] === 'user')) {
38+
for (const childKey in userResources) {
39+
if (userResources[key].isNested) {
40+
await client.indices.putMapping({
41+
index: topResources[key].index,
42+
type: topResources[key].type,
43+
include_type_name: true,
44+
body: {
45+
properties: {
46+
[userResources[childKey].propertyName]: {
47+
type: 'nested'
48+
}
49+
}
50+
}
51+
})
52+
}
53+
}
54+
}
3455
}
3556
}
3657
}

0 commit comments

Comments
 (0)
This repository has been archived.