From b574673f003c9ac5b51317bde7505841468bbfce Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 29 Jan 2024 05:26:49 +0300 Subject: [PATCH] search-indicies --- services/search.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/services/search.py b/services/search.py index 74d4c87e..25aeee29 100644 --- a/services/search.py +++ b/services/search.py @@ -10,12 +10,18 @@ from services.rediscache import redis logger = logging.getLogger('[services.search] ') logger.setLevel(logging.DEBUG) -ELASTIC_HOST = os.environ.get('ELASTIC_HOST', 'localhost').replace('https://', '').replace('http://', '') +ELASTIC_HOST = ( + os.environ.get('ELASTIC_HOST', 'localhost') + .replace('https://', '') + .replace('http://', '') +) ELASTIC_USER = os.environ.get('ELASTIC_USER', '') ELASTIC_PASSWORD = os.environ.get('ELASTIC_PASSWORD', '') ELASTIC_PORT = os.environ.get('ELASTIC_PORT', 9200) ELASTIC_AUTH = f'{ELASTIC_USER}:{ELASTIC_PASSWORD}' if ELASTIC_USER else '' -ELASTIC_URL = os.environ.get('ELASTIC_URL', f'https://{ELASTIC_AUTH}@{ELASTIC_HOST}:{ELASTIC_PORT}') +ELASTIC_URL = os.environ.get( + 'ELASTIC_URL', f'https://{ELASTIC_AUTH}@{ELASTIC_HOST}:{ELASTIC_PORT}' +) REDIS_TTL = 86400 # 1 day in seconds @@ -26,13 +32,13 @@ class SearchService: self.disabled = False try: self.client = OpenSearch( - hosts = [{'host': ELASTIC_HOST, 'port': ELASTIC_PORT}], - http_compress = True, - http_auth = (ELASTIC_USER, ELASTIC_PASSWORD), - use_ssl = True, - verify_certs = False, - ssl_assert_hostname = False, - ssl_show_warn = False, + hosts=[{'host': ELASTIC_HOST, 'port': ELASTIC_PORT}], + http_compress=True, + http_auth=(ELASTIC_USER, ELASTIC_PASSWORD), + use_ssl=True, + verify_certs=False, + ssl_assert_hostname=False, + ssl_show_warn=False, # ca_certs = ca_certs_path ) @@ -44,6 +50,13 @@ class SearchService: def info(self): logging.info(f'{self.client}') + try: + indices = self.client.indices.get_alias('*') + logger.debug('List of indices:') + for index in indices: + logger.debug(f'- {index}') + except Exception as e: + logger.error(f'Error while listing indices: {e}') def delete_index(self): self.client.indices.delete(index=self.index_name, ignore_unavailable=True) @@ -116,7 +129,9 @@ class SearchService: } } if mapping != expected_mapping: - logger.debug(f'Recreating {self.index_name} index due to incorrect mapping') + logger.debug( + f'Recreating {self.index_name} index due to incorrect mapping' + ) self.recreate_index() def recreate_index(self):