From 95c6f136a7f30f218d6339eefaa311c508d2ae18 Mon Sep 17 00:00:00 2001 From: philip Date: Thu, 26 Dec 2024 12:33:53 +0000 Subject: [PATCH] avoid exception if index not found DOAJ/doajPM#4031 --- portality/dao.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/portality/dao.py b/portality/dao.py index d234463df..948f136f2 100644 --- a/portality/dao.py +++ b/portality/dao.py @@ -1090,8 +1090,9 @@ def _yield_index_alias(): def is_exist(query: dict, index): query['size'] = 1 query['_source'] = False - res = ES.search(body=query, index=index, size=1) - return res['hits']['total']['value'] > 0 + res = ES.search(body=query, index=index, size=1, ignore=[404]) + + return res.get('hits', {}).get('total',{}).get('value', 0) > 0 class BlockTimeOutException(Exception):