logo
Browse Source

Update connection methods

Signed-off-by: Jael Gu <mengjia.gu@zilliz.com>
main
Jael Gu 3 years ago
parent
commit
664cda4313
  1. 17
      es_index.py

17
es_index.py

@ -15,21 +15,16 @@ class ESIndex(PyOperator):
Use bulk to insert docs into ElasticSearch index, using auto id generated. Use bulk to insert docs into ElasticSearch index, using auto id generated.
Args: Args:
host (`str`): host to connect ElasticSearch client
port (`int`): port to connect ElasticSearch client
index_name (`str`): index name to index input docs
user (`str=None`): user name to connect ElasticSearch client, defaults to None
password (`str=None`): user password to connect ElasticSearch client, defaults to None
ca_certs (`str=None`): path to CA certificate, defaults to None
**connection_kwargs: For example, host
""" """
def __init__(self, host: str, port: int, index_name: str, user: str = None, password: str = None, ca_certs: str = None):
def __init__(self, index_name: str, **connection_kwargs):
super().__init__() super().__init__()
self.index_name = index_name self.index_name = index_name
if 'port' in connection_kwargs:
assert 'host' in connection_kwargs, 'Missing port in connection kwargs but given port only.'
connection_kwargs['hosts'] = [f'https://{host}:{port}']
try: try:
self.client = Elasticsearch(
f'https://{host}:{port}',
ca_certs=ca_certs,
basic_auth=(user, password))
self.client = Elasticsearch(**connection_kwargs)
logger.info('Successfully connected to ElasticSearch client.') logger.info('Successfully connected to ElasticSearch client.')
except Exception as e: except Exception as e:
logger.error('Failed to connect ElasticSearch client:\n', e) logger.error('Failed to connect ElasticSearch client:\n', e)

Loading…
Cancel
Save