reindex-fix-6

This commit is contained in:
Untone 2024-02-29 14:56:50 +03:00
parent cb85e24a11
commit fc3bb52431

View File

@ -106,11 +106,15 @@ class SearchService:
else: else:
logger.debug(f' найден существующий индекс {self.index_name}') logger.debug(f' найден существующий индекс {self.index_name}')
# Check if the mapping is correct, and recreate the index if needed # Check if the mapping is correct, and recreate the index if needed
mapping = self.client.indices.get_mapping(index=self.index_name) result = self.client.indices.get_mapping(index=self.index_name)
logger.debug(f' найдена структура индексации: {mapping}') if isinstance(result, str):
if mapping != expected_mapping: result = json.loads(result)
logger.warn(' требуется другая структура индексации: пересоздаём') if isinstance(result, dict):
await self.recreate_index() mapping = result.get('mapping')
if mapping and mapping != expected_mapping:
logger.debug(f' найдена структура индексации: {mapping}')
logger.warn(' требуется другая структура индексации, переиндексация')
await self.recreate_index()
async def recreate_index(self): async def recreate_index(self):
async with self.lock: async with self.lock: