author-shouts-counter-fix
All checks were successful
Deploy to core / deploy (push) Successful in 1m49s

This commit is contained in:
2024-01-30 11:58:17 +03:00
parent e4d7284681
commit e28f03d7db
4 changed files with 15 additions and 23 deletions

View File

@@ -13,16 +13,12 @@ os_logger.setLevel(logging.INFO)
logger = logging.getLogger('\t[services.search]\t')
logger.setLevel(logging.DEBUG)
ELASTIC_HOST = (
os.environ.get('ELASTIC_HOST', '').replace('https://', '')
)
ELASTIC_HOST = os.environ.get('ELASTIC_HOST', '').replace('https://', '')
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
@@ -114,9 +110,7 @@ class SearchService:
if self.lock.acquire(blocking=False):
try:
logger.debug(f' Создаём новый индекс: {self.index_name} ')
self.client.indices.create(
index=self.index_name, body=index_settings
)
self.client.indices.create(index=self.index_name, body=index_settings)
self.client.indices.close(index=self.index_name)
self.client.indices.open(index=self.index_name)
finally:
@@ -127,9 +121,7 @@ class SearchService:
def put_mapping(self):
if self.client:
logger.debug(f' Разметка индекации {self.index_name}')
self.client.indices.put_mapping(
index=self.index_name, body=expected_mapping
)
self.client.indices.put_mapping(index=self.index_name, body=expected_mapping)
def check_index(self):
if self.client:
@@ -164,9 +156,7 @@ class SearchService:
'query': {'match': {'_all': text}},
}
if self.client:
search_response = self.client.search(
index=self.index_name, body=search_body, size=limit, from_=offset
)
search_response = self.client.search(index=self.index_name, body=search_body, size=limit, from_=offset)
hits = search_response['hits']['hits']
results = [