Skip to content

Commit bf1598d

Browse files
incorporate pr 177
1 parent cd1f3a1 commit bf1598d

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Added
1111

12-
- OpenSearch 2.11.1 support [#187](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/187)
1312
- Advanced comparison (LIKE, IN, BETWEEN) operators to the Filter extension [#178](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/178)
13+
- Collection update endpoint no longer delete all sub items [#177](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/177)
14+
- OpenSearch 2.11.1 support [#187](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/187)
1415

1516
### Changed
1617

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ services:
4343
- RELOAD=true
4444
- ENVIRONMENT=local
4545
- WEB_CONCURRENCY=10
46-
- ES_HOST=172.17.0.1
46+
- ES_HOST=opensearch
4747
- ES_PORT=9202
4848
- ES_USE_SSL=false
4949
- ES_VERIFY_CERTS=false
@@ -74,6 +74,7 @@ services:
7474
opensearch:
7575
container_name: os-container
7676
image: opensearchproject/opensearch:${OPENSEARCH_VERSION:-2.11.1}
77+
hostname: opensearch
7778
environment:
7879
- discovery.type=single-node
7980
- plugins.security.disabled=true

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config/config_opensearch.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ def _es_config() -> Dict[str, Any]:
4040
if (u := os.getenv("ES_USER")) and (p := os.getenv("ES_PASS")):
4141
config["http_auth"] = (u, p)
4242

43+
if api_key := os.getenv("ES_API_KEY"):
44+
if isinstance(config["headers"], dict):
45+
headers = {**config["headers"], "x-api-key": api_key}
46+
47+
else:
48+
config["headers"] = {"x-api-key": api_key}
49+
50+
config["headers"] = headers
51+
4352
return config
4453

4554

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ async def all_collections(self, **kwargs) -> Collections:
112112
next_link = None
113113
if len(hits) == limit:
114114
last_hit = hits[-1]
115-
logger.info(last_hit)
116115
next_search_after = last_hit["sort"]
117116
next_token = urlsafe_b64encode(
118117
",".join(map(str, next_search_after)).encode()

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic/database_logic_opensearch.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,53 @@ async def find_collection(self, collection_id: str) -> Collection:
771771
raise NotFoundError(f"Collection {collection_id} not found")
772772

773773
return collection["_source"]
774+
775+
async def update_collection(
776+
self, collection_id: str, collection: Collection, refresh: bool = False
777+
):
778+
"""Update a collection from the database.
779+
780+
Args:
781+
self: The instance of the object calling this function.
782+
collection_id (str): The ID of the collection to be updated.
783+
collection (Collection): The Collection object to be used for the update.
784+
785+
Raises:
786+
NotFoundError: If the collection with the given `collection_id` is not
787+
found in the database.
788+
789+
Notes:
790+
This function updates the collection in the database using the specified
791+
`collection_id` and with the collection specified in the `Collection` object.
792+
If the collection is not found, a `NotFoundError` is raised.
793+
"""
794+
await self.find_collection(collection_id=collection_id)
795+
796+
if collection_id != collection["id"]:
797+
await self.create_collection(collection, refresh=refresh)
798+
799+
await self.client.reindex(
800+
body={
801+
"dest": {"index": f"{ITEMS_INDEX_PREFIX}{collection['id']}"},
802+
"source": {"index": f"{ITEMS_INDEX_PREFIX}{collection_id}"},
803+
"script": {
804+
"lang": "painless",
805+
"source": f"""ctx._id = ctx._id.replace('{collection_id}', '{collection["id"]}'); ctx._source.collection = '{collection["id"]}' ;""",
806+
},
807+
},
808+
wait_for_completion=True,
809+
refresh=refresh,
810+
)
811+
812+
await self.delete_collection(collection_id)
813+
814+
else:
815+
await self.client.index(
816+
index=COLLECTIONS_INDEX,
817+
id=collection_id,
818+
body=collection,
819+
refresh=refresh,
820+
)
774821

775822
async def delete_collection(self, collection_id: str, refresh: bool = False):
776823
"""Delete a collection from the database.

0 commit comments

Comments
 (0)