Skip to content

Commit

Permalink
incorporate pr 177
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesfisher-geo committed Feb 2, 2024
1 parent cd1f3a1 commit bf1598d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added

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

### Changed

Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ services:
- RELOAD=true
- ENVIRONMENT=local
- WEB_CONCURRENCY=10
- ES_HOST=172.17.0.1
- ES_HOST=opensearch
- ES_PORT=9202
- ES_USE_SSL=false
- ES_VERIFY_CERTS=false
Expand Down Expand Up @@ -74,6 +74,7 @@ services:
opensearch:
container_name: os-container
image: opensearchproject/opensearch:${OPENSEARCH_VERSION:-2.11.1}
hostname: opensearch
environment:
- discovery.type=single-node
- plugins.security.disabled=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ def _es_config() -> Dict[str, Any]:
if (u := os.getenv("ES_USER")) and (p := os.getenv("ES_PASS")):
config["http_auth"] = (u, p)

if api_key := os.getenv("ES_API_KEY"):
if isinstance(config["headers"], dict):
headers = {**config["headers"], "x-api-key": api_key}

else:
config["headers"] = {"x-api-key": api_key}

config["headers"] = headers

return config


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ async def all_collections(self, **kwargs) -> Collections:
next_link = None
if len(hits) == limit:
last_hit = hits[-1]
logger.info(last_hit)
next_search_after = last_hit["sort"]
next_token = urlsafe_b64encode(
",".join(map(str, next_search_after)).encode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,53 @@ async def find_collection(self, collection_id: str) -> Collection:
raise NotFoundError(f"Collection {collection_id} not found")

return collection["_source"]

async def update_collection(
self, collection_id: str, collection: Collection, refresh: bool = False
):
"""Update a collection from the database.
Args:
self: The instance of the object calling this function.
collection_id (str): The ID of the collection to be updated.
collection (Collection): The Collection object to be used for the update.
Raises:
NotFoundError: If the collection with the given `collection_id` is not
found in the database.
Notes:
This function updates the collection in the database using the specified
`collection_id` and with the collection specified in the `Collection` object.
If the collection is not found, a `NotFoundError` is raised.
"""
await self.find_collection(collection_id=collection_id)

if collection_id != collection["id"]:
await self.create_collection(collection, refresh=refresh)

await self.client.reindex(
body={
"dest": {"index": f"{ITEMS_INDEX_PREFIX}{collection['id']}"},
"source": {"index": f"{ITEMS_INDEX_PREFIX}{collection_id}"},
"script": {
"lang": "painless",
"source": f"""ctx._id = ctx._id.replace('{collection_id}', '{collection["id"]}'); ctx._source.collection = '{collection["id"]}' ;""",
},
},
wait_for_completion=True,
refresh=refresh,
)

await self.delete_collection(collection_id)

else:
await self.client.index(
index=COLLECTIONS_INDEX,
id=collection_id,
body=collection,
refresh=refresh,
)

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

0 comments on commit bf1598d

Please sign in to comment.