This commit is contained in:
parent
e6366d15f6
commit
e6f12e9106
|
@ -13,12 +13,16 @@ 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://', '').replace('http://', '')
|
||||
ELASTIC_HOST = (
|
||||
os.environ.get('ELASTIC_HOST', '').replace('https://', '').replace('http://', '')
|
||||
)
|
||||
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
|
||||
|
||||
|
||||
|
@ -100,15 +104,18 @@ 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:
|
||||
self.lock.release()
|
||||
else:
|
||||
logger.debug(' ..')
|
||||
except Exception as error:
|
||||
logging.warning(f' {error}')
|
||||
except Exception as _error: # noqa: S110
|
||||
# logging.warning(f' {error}')
|
||||
pass
|
||||
|
||||
def put_mapping(self):
|
||||
mapping = {
|
||||
|
@ -142,7 +149,9 @@ class SearchService:
|
|||
def recreate_index(self):
|
||||
if self.lock.acquire(blocking=False):
|
||||
try:
|
||||
logger.debug(f' Удаляем индекс {self.index_name} из-за неправильной структуры данных')
|
||||
logger.debug(
|
||||
f' Удаляем индекс {self.index_name} из-за неправильной структуры данных'
|
||||
)
|
||||
self.delete_index()
|
||||
self.check_index()
|
||||
finally:
|
||||
|
@ -162,7 +171,9 @@ 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 = [
|
||||
|
|
Loading…
Reference in New Issue
Block a user