Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion stac_fastapi/core/stac_fastapi/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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", [])},
)


Expand All @@ -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
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down