88from typing import Any , Dict , Iterable , List , Optional , Tuple , Type
99
1010import attr
11+ import elasticsearch .helpers as helpers
1112from elasticsearch .dsl import Q , Search
13+ from elasticsearch .exceptions import NotFoundError as ESNotFoundError
1214from starlette .requests import Request
1315
14- from elasticsearch import exceptions , helpers # type: ignore
1516from stac_fastapi .core .base_database_logic import BaseDatabaseLogic
1617from stac_fastapi .core .database_logic import (
1718 COLLECTIONS_INDEX ,
@@ -271,7 +272,7 @@ async def get_one_item(self, collection_id: str, item_id: str) -> Dict:
271272 index = index_alias_by_collection_id (collection_id ),
272273 id = mk_item_id (item_id , collection_id ),
273274 )
274- except exceptions . NotFoundError :
275+ except ESNotFoundError :
275276 raise NotFoundError (
276277 f"Item { item_id } does not exist inside Collection { collection_id } "
277278 )
@@ -511,7 +512,7 @@ async def execute_search(
511512
512513 try :
513514 es_response = await search_task
514- except exceptions . NotFoundError :
515+ except ESNotFoundError :
515516 raise NotFoundError (f"Collections '{ collection_ids } ' do not exist" )
516517
517518 hits = es_response ["hits" ]["hits" ]
@@ -594,7 +595,7 @@ def _fill_aggregation_parameters(name: str, agg: dict) -> dict:
594595
595596 try :
596597 db_response = await search_task
597- except exceptions . NotFoundError :
598+ except ESNotFoundError :
598599 raise NotFoundError (f"Collections '{ collection_ids } ' do not exist" )
599600
600601 return db_response
@@ -720,7 +721,7 @@ async def delete_item(
720721 id = mk_item_id (item_id , collection_id ),
721722 refresh = refresh ,
722723 )
723- except exceptions . NotFoundError :
724+ except ESNotFoundError :
724725 raise NotFoundError (
725726 f"Item { item_id } in collection { collection_id } not found"
726727 )
@@ -740,7 +741,7 @@ async def get_items_mapping(self, collection_id: str) -> Dict[str, Any]:
740741 index = index_name , allow_no_indices = False
741742 )
742743 return mapping .body
743- except exceptions . NotFoundError :
744+ except ESNotFoundError :
744745 raise NotFoundError (f"Mapping for index { index_name } not found" )
745746
746747 async def create_collection (self , collection : Collection , refresh : bool = False ):
@@ -791,7 +792,7 @@ async def find_collection(self, collection_id: str) -> Collection:
791792 collection = await self .client .get (
792793 index = COLLECTIONS_INDEX , id = collection_id
793794 )
794- except exceptions . NotFoundError :
795+ except ESNotFoundError :
795796 raise NotFoundError (f"Collection { collection_id } not found" )
796797
797798 return collection ["_source" ]
0 commit comments