Skip to content

[FIX-132] - Closing ES client connections in ES index management functions #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.3.0...main>
[v0.3.0]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.2.0...v0.3.0>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]:
Expand Down