Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 55c8582

Browse files
Update elasticsearch host to support elastic cloud since we are using enrich feature, which is unsupported by AWS ES
1 parent 5e59887 commit 55c8582

File tree

5 files changed

+23
-25
lines changed

5 files changed

+23
-25
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The following parameters can be set in config files or in env variables:
2727
- GROUPS_MEMBER_ADD_TOPIC: the add groups member Kafka message topic, default value is 'groups.notification.member.add'
2828
- GROUPS_MEMBER_DELETE_TOPIC: the delete groups member Kafka message topic, default value is 'groups.notification.member.delete'
2929
- GROUPS_MEMBERSHIP_TYPE: the groups membership type that should be processed, default value is 'user'
30-
- ES.HOST: Elasticsearch host, default value is 'localhost:9200'
30+
- ES_HOST: Elasticsearch host, default value is 'localhost:9200'
3131
- ES.AWS_REGION: The Amazon region to use when using AWS Elasticsearch service, default value is 'us-east-1'
3232
- ES.ACHIEVEMENT_PROVIDER_INDEX: Elasticsearch index name for achievement provider, default value is 'achievement_provider'
3333
- ES.ACHIEVEMENT_PROVIDER_TYPE: Elasticsearch index type for achievement provider, default value is '_doc'
@@ -61,7 +61,9 @@ The following parameters can be set in config files or in env variables:
6161
- ACHIEVEMENT_PROVIDER_ENRICH_POLICYNAME: The enrich policy for achievement provider. Default is `achievementprovider-policy`
6262
- SKILL_ENRICH_POLICYNAME: The enrich policy for skill. Default is `skill-policy`
6363
- ATTRIBUTE_ENRICH_POLICYNAME: The enrich policy for skill. Default is `attribute-policy`
64-
64+
- ELASTICCLOUD_ID: The elastic cloud id, if your elasticsearch instance is hosted on elastic cloud. DO NOT provide a value for ES_HOST if you are using this
65+
- ELASTICCLOUD_USERNAME: The elastic cloud username for basic authentication. Provide this only if your elasticsearch instance is hosted on elastic cloud
66+
- ELASTICCLOUD_PASSWORD: The elastic cloud password for basic authentication. Provide this only if your elasticsearch instance is hosted on elastic cloud
6567

6668
There is a `/health` endpoint that checks for the health of the app. This sets up an expressjs server and listens on the environment variable `PORT`. It's not part of the configuration file and needs to be passed as an environment variable
6769

config/default.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ module.exports = {
2424

2525
ES: {
2626
HOST: process.env.ES_HOST || 'http://localhost:9200',
27+
28+
ELASTICCLOUD: {
29+
id: process.env.ELASTICCLOUD_ID,
30+
username: process.env.ELASTICCLOUD_USERNAME,
31+
password: process.env.ELASTICCLOUD_PASSWORD
32+
},
33+
2734
AWS_REGION: process.env.AWS_REGION || 'us-east-1', // AWS Region to be used if we use AWS ES
2835
ACHIEVEMENT_PROVIDER_INDEX: process.env.ACHIEVEMENT_PROVIDER_INDEX || 'achievement_provider',
2936
ACHIEVEMENT_PROVIDER_TYPE: process.env.ACHIEVEMENT_PROVIDER_TYPE || '_doc',

package-lock.json

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"@elastic/elasticsearch": "^7.9.1",
3030
"@hapi/joi": "^15.1.0",
3131
"async-mutex": "^0.2.4",
32-
"aws-elasticsearch-connector": "^9.0.0",
3332
"aws-sdk": "^2.476.0",
3433
"bluebird": "^3.5.5",
3534
"config": "^3.1.0",

src/common/helper.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
const AWS = require('aws-sdk')
66
const config = require('config')
77
const elasticsearch = require('@elastic/elasticsearch')
8-
const createAwsElasticsearchConnector = require('aws-elasticsearch-connector')
98
const _ = require('lodash')
109
const Joi = require('@hapi/joi')
1110
const { Mutex } = require('async-mutex')
@@ -40,15 +39,19 @@ async function getESClient () {
4039
return esClient
4140
}
4241
const host = config.ES.HOST
42+
const cloudId = config.ES.ELASTICCLOUD.id
4343

44-
// AWS ES configuration is different from other providers
45-
if (/.*amazonaws.*/.test(host)) {
46-
try {
47-
esClient = new elasticsearch.Client({
48-
...createAwsElasticsearchConnector(AWS.config),
49-
node: host
50-
})
51-
} catch (error) { console.log(error) }
44+
if (cloudId) {
45+
// Elastic Cloud configuration
46+
esClient = new elasticsearch.Client({
47+
cloud: {
48+
id: cloudId
49+
},
50+
auth: {
51+
username: config.ES.ELASTICCLOUD.username,
52+
password: config.ES.ELASTICCLOUD.password
53+
}
54+
})
5255
} else {
5356
esClient = new elasticsearch.Client({
5457
node: host

0 commit comments

Comments
 (0)