From fc3bb52431c845972509a79cfa9f055123cc54d6 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 29 Feb 2024 14:56:50 +0300 Subject: [PATCH] reindex-fix-6 --- services/search.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/services/search.py b/services/search.py index 676778dc..de05c6ed 100644 --- a/services/search.py +++ b/services/search.py @@ -106,11 +106,15 @@ class SearchService: else: logger.debug(f' найден существующий индекс {self.index_name}') # Check if the mapping is correct, and recreate the index if needed - mapping = self.client.indices.get_mapping(index=self.index_name) - logger.debug(f' найдена структура индексации: {mapping}') - if mapping != expected_mapping: - logger.warn(' требуется другая структура индексации: пересоздаём') - await self.recreate_index() + result = self.client.indices.get_mapping(index=self.index_name) + if isinstance(result, str): + result = json.loads(result) + if isinstance(result, dict): + 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 with self.lock: