diff --git a/CHANGELOG.md b/CHANGELOG.md index 0016eecb..8600795d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed ### Fixed +- Corrected the closing of client connections in ES index management functions [#132](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/132) + ## [v0.3.0] ### Added @@ -59,7 +61,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. Previously, there was no sort order defined. - Db_to_stac serializer moved to core.py for consistency as it existed in both core and database_logic previously. - Use genexp in execute_search and get_all_collections to return results. -- Added db_to_stac serializer to item_collection method in core.py. +- Added db_to_stac serializer to item_collection method in core.py. [Unreleased]: [v0.3.0]: diff --git a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py index 0c9d80ff..a59e5b2c 100644 --- a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py +++ b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py @@ -140,29 +140,36 @@ def indices(collection_ids: Optional[List[str]]) -> str: async def create_collection_index() -> None: - """Create the index for Items and Collections.""" - await AsyncElasticsearchSettings().create_client.indices.create( + """Create the index for Collections.""" + client = AsyncElasticsearchSettings().create_client + + await client.indices.create( index=COLLECTIONS_INDEX, mappings=ES_COLLECTIONS_MAPPINGS, ignore=400, # ignore 400 already exists code ) + await client.close() async def create_item_index(collection_id: str): - """Create the index for Items and Collections.""" - await AsyncElasticsearchSettings().create_client.indices.create( + """Create the index for Items.""" + client = AsyncElasticsearchSettings().create_client + + await client.indices.create( index=index_by_collection_id(collection_id), mappings=ES_ITEMS_MAPPINGS, settings=ES_ITEMS_SETTINGS, ignore=400, # ignore 400 already exists code ) + await client.close() async def delete_item_index(collection_id: str): - """Create the index for Items and Collections.""" - await AsyncElasticsearchSettings().create_client.indices.delete( - index=index_by_collection_id(collection_id) - ) + """Delete the index for Items.""" + client = AsyncElasticsearchSettings().create_client + + await client.indices.delete(index=index_by_collection_id(collection_id)) + await client.close() def bbox2polygon(b0: float, b1: float, b2: float, b3: float) -> List[List[List[float]]]: