Skip to content

Commit 5f97ae1

Browse files
Merge pull request #8 from Gathondu/develop
Refactor code
2 parents c255362 + 181eef9 commit 5f97ae1

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

healthtools_ke_api/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
# Elastic Search configs
1414
ES = {
15-
"host": os.getenv("ES_HOST", None),
15+
"host": os.getenv("ES_HOST", "127.0.0.1"),
16+
"port": os.getenv("ES_PORT", "9200"),
1617
"index": "healthtools"
1718
}
1819

healthtools_ke_api/views/elastic_search.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ class Elastic(object):
1010
Common class for elastic search client and methods
1111
"""
1212
def __init__(self):
13-
# set up authentication credentials
14-
awsauth = AWS4Auth(AWS["aws_access_key_id"], AWS["aws_secret_access_key"], AWS["region_name"], 'es')
1513
# client host for aws elastic search service
16-
if ES['host']:
14+
if 'aws' in ES['host']:
15+
# set up authentication credentials
16+
awsauth = AWS4Auth(AWS["aws_access_key_id"], AWS["aws_secret_access_key"], AWS["region_name"], 'es')
1717
self.es_client = Elasticsearch(
1818
hosts=ES['host'],
19-
port=443,
19+
port=ES['port'],
2020
http_auth=awsauth,
2121
use_ssl=True,
2222
verify_certs=True,
2323
connection_class=RequestsHttpConnection,
2424
serializer=JSONSerializerPython2()
2525
)
2626
else:
27-
self.es_client = Elasticsearch('127.0.0.1')
27+
self.es_client = Elasticsearch("{}:{}".format(ES['host'], ES['port']))
2828

2929
@staticmethod
3030
def remove_keyword(query):

0 commit comments

Comments
 (0)