diff --git a/CHANGELOG.md b/CHANGELOG.md index 130f5df6..21d9fd13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed +- Changed assets serialization to prevent mapping explosion while allowing asset inforamtion to be indexed. [#341](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/341) + ### Fixed ## [v6.2.1] - 2025-09-02 diff --git a/stac_fastapi/core/stac_fastapi/core/serializers.py b/stac_fastapi/core/stac_fastapi/core/serializers.py index d537b493..22546703 100644 --- a/stac_fastapi/core/stac_fastapi/core/serializers.py +++ b/stac_fastapi/core/stac_fastapi/core/serializers.py @@ -66,6 +66,10 @@ def stac_to_db(cls, stac_data: stac_types.Item, base_url: str) -> stac_types.Ite item_links = resolve_links(stac_data.get("links", []), base_url) stac_data["links"] = item_links + stac_data["assets"] = [ + {"es_key": k, **v} for k, v in stac_data.get("assets", {}).items() + ] + now = now_to_rfc3339_str() if "created" not in stac_data["properties"]: stac_data["properties"]["created"] = now @@ -103,7 +107,7 @@ def db_to_stac(cls, item: dict, base_url: str) -> stac_types.Item: bbox=item.get("bbox", []), properties=item.get("properties", {}), links=item_links, - assets=item.get("assets", {}), + assets={a.pop("es_key"): a for a in item.get("assets", [])}, ) @@ -128,6 +132,9 @@ def stac_to_db( collection["links"] = resolve_links( collection.get("links", []), str(request.base_url) ) + collection["assets"] = [ + {"es_key": k, **v} for k, v in collection.get("assets", {}).items() + ] return collection @classmethod @@ -174,5 +181,9 @@ def db_to_stac( collection_links += resolve_links(original_links, str(request.base_url)) collection["links"] = collection_links + collection["assets"] = { + a.pop("es_key"): a for a in collection.get("assets", []) + } + # Return the stac_types.Collection object return stac_types.Collection(**collection) diff --git a/stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/mappings.py b/stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/mappings.py index 476d656a..935aa84b 100644 --- a/stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/mappings.py +++ b/stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/mappings.py @@ -134,7 +134,7 @@ class Geometry(Protocol): # noqa "id": {"type": "keyword"}, "collection": {"type": "keyword"}, "geometry": {"type": "geo_shape"}, - "assets": {"type": "object", "enabled": False}, + "assets": {"type": "object"}, "links": {"type": "object", "enabled": False}, "properties": { "type": "object",