|
12 | 12 | from opensearchpy.helpers.search import Search |
13 | 13 |
|
14 | 14 | from stac_fastapi.core import serializers |
15 | | -from stac_fastapi.elasticsearch.config.config_opensearch import AsyncSearchSettings |
16 | | -from stac_fastapi.elasticsearch.config.config_opensearch import ( |
17 | | - SearchSettings as SyncSearchSettings, |
| 15 | +from stac_fastapi.core.extensions import filter |
| 16 | +from stac_fastapi.core.utilities import bbox2polygon |
| 17 | +from stac_fastapi.opensearch.config import ( |
| 18 | + AsyncOpensearchSettings as AsyncSearchSettings, |
18 | 19 | ) |
19 | | -from stac_fastapi.elasticsearch.extensions import filter |
20 | | -from stac_fastapi.elasticsearch.utilities import bbox2polygon |
| 20 | +from stac_fastapi.opensearch.config import OpensearchSettings as SyncSearchSettings |
21 | 21 | from stac_fastapi.types.errors import ConflictError, NotFoundError |
22 | 22 | from stac_fastapi.types.stac import Collection, Item |
23 | 23 |
|
@@ -772,6 +772,54 @@ async def find_collection(self, collection_id: str) -> Collection: |
772 | 772 |
|
773 | 773 | return collection["_source"] |
774 | 774 |
|
| 775 | + # this is copied from stac-fastapi-elasticseach and the logic needs to be updated for opensearch |
| 776 | + async def update_collection( |
| 777 | + self, collection_id: str, collection: Collection, refresh: bool = False |
| 778 | + ): |
| 779 | + """Update a collection from the database. |
| 780 | +
|
| 781 | + Args: |
| 782 | + self: The instance of the object calling this function. |
| 783 | + collection_id (str): The ID of the collection to be updated. |
| 784 | + collection (Collection): The Collection object to be used for the update. |
| 785 | +
|
| 786 | + Raises: |
| 787 | + NotFoundError: If the collection with the given `collection_id` is not |
| 788 | + found in the database. |
| 789 | +
|
| 790 | + Notes: |
| 791 | + This function updates the collection in the database using the specified |
| 792 | + `collection_id` and with the collection specified in the `Collection` object. |
| 793 | + If the collection is not found, a `NotFoundError` is raised. |
| 794 | + """ |
| 795 | + await self.find_collection(collection_id=collection_id) |
| 796 | + |
| 797 | + if collection_id != collection["id"]: |
| 798 | + await self.create_collection(collection, refresh=refresh) |
| 799 | + |
| 800 | + await self.client.reindex( |
| 801 | + body={ |
| 802 | + "dest": {"index": f"{ITEMS_INDEX_PREFIX}{collection['id']}"}, |
| 803 | + "source": {"index": f"{ITEMS_INDEX_PREFIX}{collection_id}"}, |
| 804 | + "script": { |
| 805 | + "lang": "painless", |
| 806 | + "source": f"""ctx._id = ctx._id.replace('{collection_id}', '{collection["id"]}'); ctx._source.collection = '{collection["id"]}' ;""", |
| 807 | + }, |
| 808 | + }, |
| 809 | + wait_for_completion=True, |
| 810 | + refresh=refresh, |
| 811 | + ) |
| 812 | + |
| 813 | + await self.delete_collection(collection_id) |
| 814 | + |
| 815 | + else: |
| 816 | + await self.client.index( |
| 817 | + index=COLLECTIONS_INDEX, |
| 818 | + id=collection_id, |
| 819 | + document=collection, |
| 820 | + refresh=refresh, |
| 821 | + ) |
| 822 | + |
775 | 823 | async def delete_collection(self, collection_id: str, refresh: bool = False): |
776 | 824 | """Delete a collection from the database. |
777 | 825 |
|
|
0 commit comments