check-if-exists
All checks were successful
Deploy to core / deploy (push) Successful in 1m33s

This commit is contained in:
Untone 2024-01-29 05:13:37 +03:00
parent f38ee9239f
commit 4a6863c474
2 changed files with 15 additions and 4 deletions

View File

@ -45,7 +45,7 @@ poetry run main.py
### search.py
Позволяет получать результаты пользовательских поисковых запросов в кешируемом виде от ElasticSearch с оценкой `score`, объединенные с запросами к базе данных, запрашиваем через GraphQL API `load_shouts_search`. Требует установка `ELASTIC_URL` (можно отдельными компонентами) и, опционально, обновляет индекс на старте если переменная `ELASTIC_REINDEX` задана.
Позволяет получать результаты пользовательских поисковых запросов в кешируемом виде от ElasticSearch с оценкой `score`, объединенные с запросами к базе данных, запрашиваем через GraphQL API `load_shouts_search`. Требует установка `ELASTIC_URL` (можно отдельными компонентами).
### notify.py

View File

@ -40,10 +40,8 @@ class SearchService:
except Exception as exc:
logger.error(exc)
self.disabled = True
self.check_index()
if ELASTIC_REINDEX:
self.recreate_index()
self.check_index()
def info(self):
logging.info(f'{self.client}')
@ -108,6 +106,19 @@ class SearchService:
logger.debug(f'Creating {self.index_name} index')
self.create_index()
self.put_mapping()
else:
# Check if the mapping is correct, and recreate the index if needed
mapping = self.client.indices.get_mapping(index=self.index_name)
expected_mapping = {
'properties': {
'body': {'type': 'text', 'analyzer': 'ru'},
'text': {'type': 'text'},
'author': {'type': 'text'},
}
}
if mapping != expected_mapping:
logger.debug(f'Recreating {self.index_name} index due to incorrect mapping')
self.recreate_index()
def recreate_index(self):
self.delete_index()