This commit is contained in:
parent
0f5df77d28
commit
0051492bd3
|
@ -20,10 +20,7 @@ REDIS_TTL = 86400 # 1 день в секундах
|
||||||
|
|
||||||
index_settings = {
|
index_settings = {
|
||||||
"settings": {
|
"settings": {
|
||||||
"index": {
|
"index": {"number_of_shards": 1, "auto_expand_replicas": "0-all"},
|
||||||
"number_of_shards": 1,
|
|
||||||
"auto_expand_replicas": "0-all"
|
|
||||||
},
|
|
||||||
"analysis": {
|
"analysis": {
|
||||||
"analyzer": {
|
"analyzer": {
|
||||||
"ru": {
|
"ru": {
|
||||||
|
@ -40,21 +37,9 @@ index_settings = {
|
||||||
"mappings": {
|
"mappings": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"body": {"type": "text", "analyzer": "ru"},
|
"body": {"type": "text", "analyzer": "ru"},
|
||||||
# "cover": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},
|
|
||||||
# "created_at": {"type": "long"},
|
|
||||||
# "created_by": {"type": "long"},
|
|
||||||
# "featured_at": {"type": "long"},
|
|
||||||
# "id": {"type": "long"},
|
|
||||||
# "lang": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},
|
|
||||||
# "layout": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},
|
|
||||||
"lead": {"type": "text", "analyzer": "ru"},
|
|
||||||
"media": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},
|
|
||||||
# "oid": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},
|
|
||||||
# "published_at": {"type": "long"},
|
|
||||||
# "slug": {"type": "text", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}},
|
|
||||||
"subtitle": {"type": "text", "analyzer": "ru"},
|
|
||||||
"title": {"type": "text", "analyzer": "ru"},
|
"title": {"type": "text", "analyzer": "ru"},
|
||||||
# "updated_at": {"type": "long"}
|
"subtitle": {"type": "text", "analyzer": "ru"},
|
||||||
|
"lead": {"type": "text", "analyzer": "ru"},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -64,11 +49,12 @@ expected_mapping = index_settings["mappings"]
|
||||||
# Создание цикла событий
|
# Создание цикла событий
|
||||||
search_loop = asyncio.get_event_loop()
|
search_loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
|
||||||
def get_indices_stats():
|
def get_indices_stats():
|
||||||
indices_stats = search_service.client.cat.indices(format="json")
|
indices_stats = search_service.client.cat.indices(format="json")
|
||||||
for index_info in indices_stats:
|
for index_info in indices_stats:
|
||||||
index_name = index_info["index"]
|
index_name = index_info["index"]
|
||||||
if not index_name.startswith('.'):
|
if not index_name.startswith("."):
|
||||||
index_health = index_info["health"]
|
index_health = index_info["health"]
|
||||||
index_status = index_info["status"]
|
index_status = index_info["status"]
|
||||||
pri_shards = index_info["pri"]
|
pri_shards = index_info["pri"]
|
||||||
|
@ -154,13 +140,14 @@ class SearchService:
|
||||||
mapping = result.get(self.index_name, {}).get("mappings")
|
mapping = result.get(self.index_name, {}).get("mappings")
|
||||||
if mapping and mapping != expected_mapping:
|
if mapping and mapping != expected_mapping:
|
||||||
logger.debug(f"Найдена структура индексации: {mapping}")
|
logger.debug(f"Найдена структура индексации: {mapping}")
|
||||||
logger.warn("[!!!] Требуется другая структура индексации и переиндексация всех данных")
|
logger.warn(
|
||||||
|
"[!!!] Требуется другая структура индексации и переиндексация всех данных"
|
||||||
|
)
|
||||||
self.delete_index()
|
self.delete_index()
|
||||||
self.client = None
|
self.client = None
|
||||||
else:
|
else:
|
||||||
logger.error("клиент не инициализован, невозможно проверить индекс")
|
logger.error("клиент не инициализован, невозможно проверить индекс")
|
||||||
|
|
||||||
|
|
||||||
def index(self, shout):
|
def index(self, shout):
|
||||||
if self.client:
|
if self.client:
|
||||||
logger.debug(f"Индексируем пост {shout.id}")
|
logger.debug(f"Индексируем пост {shout.id}")
|
||||||
|
@ -177,11 +164,7 @@ class SearchService:
|
||||||
|
|
||||||
async def perform_index(self, shout, index_body):
|
async def perform_index(self, shout, index_body):
|
||||||
if self.client:
|
if self.client:
|
||||||
self.client.index(
|
self.client.index(index=self.index_name, id=str(shout.id), body=index_body)
|
||||||
index=self.index_name,
|
|
||||||
id=str(shout.id),
|
|
||||||
body=index_body
|
|
||||||
)
|
|
||||||
|
|
||||||
async def search(self, text, limit, offset):
|
async def search(self, text, limit, offset):
|
||||||
logger.debug(f"Ищем: {text}")
|
logger.debug(f"Ищем: {text}")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user