search-indicies
All checks were successful
Deploy to core / deploy (push) Successful in 1m35s

This commit is contained in:
Untone 2024-01-29 05:26:49 +03:00
parent 62018534fd
commit b574673f00

View File

@ -10,12 +10,18 @@ from services.rediscache import redis
logger = logging.getLogger('[services.search] ') logger = logging.getLogger('[services.search] ')
logger.setLevel(logging.DEBUG) 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_USER = os.environ.get('ELASTIC_USER', '')
ELASTIC_PASSWORD = os.environ.get('ELASTIC_PASSWORD', '') ELASTIC_PASSWORD = os.environ.get('ELASTIC_PASSWORD', '')
ELASTIC_PORT = os.environ.get('ELASTIC_PORT', 9200) ELASTIC_PORT = os.environ.get('ELASTIC_PORT', 9200)
ELASTIC_AUTH = f'{ELASTIC_USER}:{ELASTIC_PASSWORD}' if ELASTIC_USER else '' 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 REDIS_TTL = 86400 # 1 day in seconds
@ -44,6 +50,13 @@ class SearchService:
def info(self): def info(self):
logging.info(f'{self.client}') 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): def delete_index(self):
self.client.indices.delete(index=self.index_name, ignore_unavailable=True) self.client.indices.delete(index=self.index_name, ignore_unavailable=True)
@ -116,7 +129,9 @@ class SearchService:
} }
} }
if mapping != expected_mapping: 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() self.recreate_index()
def recreate_index(self): def recreate_index(self):