Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit fb8bd4b

Browse files
author
tkostuch
committed
create one ES client instance
1 parent c333ce9 commit fb8bd4b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/lib/elastic.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function getHits (result) {
7373
}
7474
}
7575

76+
let esClient = null
7677
function getClient (config) {
7778
let { host, port, protocol, apiVersion, requestTimeout } = config.elasticsearch
7879
const node = `${protocol}://${host}:${port}`
@@ -83,7 +84,11 @@ function getClient (config) {
8384
auth = { username: user, password }
8485
}
8586

86-
return new es.Client({ node, auth, apiVersion, requestTimeout })
87+
if (!esClient) {
88+
esClient = new es.Client({ node, auth, apiVersion, requestTimeout })
89+
}
90+
91+
return esClient
8792
}
8893

8994
function putAlias (db, originalName, aliasName, next) {

0 commit comments

Comments
 (0)