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

Commit 3c9720f

Browse files
committed
Small refactor, graphql
1 parent 681d726 commit 3c9720f

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

docker-compose.elastic7.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.0'
22
services:
33
es7:
4-
container_name: elasticsearch7
4+
container_name: es7
55
build: docker/elasticsearch7/
66
ulimits:
77
memlock:
@@ -12,6 +12,11 @@ services:
1212
ports:
1313
- '9200:9200'
1414
- '9300:9300'
15+
environment:
16+
- discovery.type=single-node
17+
- cluster.name=docker-cluster
18+
- bootstrap.memory_lock=true
19+
- "ES_JAVA_OPTS=-Xmx512m -Xms512m"
1520

1621
redis:
1722
image: 'redis:4-alpine'

docker-compose.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3.0'
1+
version: '2.0'
22
services:
33
es1:
44
container_name: elasticsearch
@@ -7,14 +7,18 @@ services:
77
memlock:
88
soft: -1
99
hard: -1
10+
mem_limit: 1g
1011
volumes:
1112
- ./docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
1213
- ./docker/elasticsearch/data:/usr/share/elasticsearch/data
1314
ports:
1415
- '9200:9200'
1516
- '9300:9300'
1617
environment:
17-
ES_JAVA_OPTS: "-Xmx512m -Xms512m"
18+
- discovery.type=single-node
19+
- cluster.name=docker-cluster
20+
- bootstrap.memory_lock=true
21+
- "ES_JAVA_OPTS=-Xmx512m -Xms512m"
1822

1923
kibana:
2024
build: docker/kibana/

src/graphql/elasticsearch/client.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import config from 'config';
2-
import elasticsearch from '@elastic/elasticsearch';
2+
import es from '../../lib/elastic'
33

4-
const client = new elasticsearch.Client({
5-
node: `${config.elasticsearch.protocol}://${config.elasticsearch.host}:${config.elasticsearch.port}`
6-
});
7-
8-
export default client;
4+
export default es.getClient(config)

src/lib/elastic.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ function _updateQueryStringParameter (uri, key, value) {
2323
}
2424
}
2525

26+
27+
function adjustIndexName (indexName, entityType, config) {
28+
if (parseInt(config.elasticsearch.apiVersion) < 6) {
29+
return indexName
30+
} else {
31+
return `${indexName}_${entityType}`
32+
}
33+
}
34+
35+
2636
function adjustBackendProxyUrl (req, indexName, entityType, config) {
2737
let url
2838
if (parseInt(config.elasticsearch.apiVersion) < 6) { // legacy for ES 5
@@ -35,7 +45,7 @@ function adjustBackendProxyUrl (req, indexName, entityType, config) {
3545
delete parsedQuery._source_exclude
3646
delete parsedQuery._source_include
3747
delete parsedQuery.request
38-
url = config.elasticsearch.host + ':' + config.elasticsearch.port + '/' + `${indexName}_${entityType}` + '/_search?' + queryString.stringify(parsedQuery)
48+
url = config.elasticsearch.host + ':' + config.elasticsearch.port + '/' + adjustIndexName(indexName, entityType, config) + '/_search?' + queryString.stringify(parsedQuery)
3949
}
4050
if (!url.startsWith('http')) {
4151
url = config.elasticsearch.protocol + '://' + url
@@ -46,9 +56,8 @@ function adjustBackendProxyUrl (req, indexName, entityType, config) {
4656
function adjustQuery (esQuery, entityType, config) {
4757
if (parseInt(config.elasticsearch.apiVersion) < 6) {
4858
esQuery.type = entityType
49-
} else {
50-
esQuery.index = `${esQuery.index}_${entityType}`
5159
}
60+
esQuery.index = adjustIndexName(esQuery.index, entityType, config)
5261
return esQuery
5362
}
5463

@@ -271,5 +280,6 @@ module.exports = {
271280
adjustBackendProxyUrl,
272281
getClient,
273282
getHits,
283+
adjustIndexName,
274284
putMappings
275285
}

0 commit comments

Comments
 (0)