Skip to content

Commit

Permalink
feat(elasticsearch): support local connection (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
elraphty authored Nov 15, 2024
1 parent 7f10154 commit e7c0144
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
ES_USERNAME = os.getenv("ES_USERNAME")
ES_PASSWORD = os.getenv("ES_PASSWORD")
ES_INDEX = os.getenv("ES_INDEX")
ES_LOCAL_URL = os.getenv("ES_LOCAL_URL")
ES_DATA_FETCH_SIZE = 10000 # No. of data to fetch and save from elastic-search
14 changes: 9 additions & 5 deletions src/elasticsearch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from elasticsearch.helpers import scan
from loguru import logger

from src.config import ES_CLOUD_ID, ES_USERNAME, ES_PASSWORD, ES_DATA_FETCH_SIZE
from src.config import ES_CLOUD_ID, ES_USERNAME, ES_PASSWORD, ES_DATA_FETCH_SIZE, ES_LOCAL_URL


class ElasticSearchClient:
Expand All @@ -18,10 +18,14 @@ def __init__(self,
self._es_username = es_username
self._es_password = es_password
self._es_data_fetch_size = es_data_fetch_size
self._es_client = Elasticsearch(
cloud_id=self._es_cloud_id,
http_auth=(self._es_username, self._es_password),
)

if ES_LOCAL_URL is not None and ES_CLOUD_ID is None:
self._es_client = Elasticsearch(ES_LOCAL_URL)
else:
self._es_client = Elasticsearch(
cloud_id=self._es_cloud_id,
http_auth=(self._es_username, self._es_password),
)

@property
def es_client(self):
Expand Down

0 comments on commit e7c0144

Please sign in to comment.