Skip to content

Commit 8974c38

Browse files
authored
Enabling asset indexing (#341)
**Description:** There are a number of extensions that include extra fields within an Item's assets. It would be useful to allow users to filter items based on these fields. Mapping assets from an Object to a Array of Objects prevents "mapping explosion" from asset keys without needing to disable indexing on the assets. It does have some search implications. See first "note" [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html). **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [x] Documentation has been updated to reflect changes, if applicable - [x] Changes are added to the changelog
1 parent 7f269e4 commit 8974c38

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212

1313
### Changed
1414

15+
- 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)
16+
1517
### Fixed
1618

1719
## [v6.2.1] - 2025-09-02

stac_fastapi/core/stac_fastapi/core/serializers.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def stac_to_db(cls, stac_data: stac_types.Item, base_url: str) -> stac_types.Ite
6666
item_links = resolve_links(stac_data.get("links", []), base_url)
6767
stac_data["links"] = item_links
6868

69+
stac_data["assets"] = [
70+
{"es_key": k, **v} for k, v in stac_data.get("assets", {}).items()
71+
]
72+
6973
now = now_to_rfc3339_str()
7074
if "created" not in stac_data["properties"]:
7175
stac_data["properties"]["created"] = now
@@ -103,7 +107,7 @@ def db_to_stac(cls, item: dict, base_url: str) -> stac_types.Item:
103107
bbox=item.get("bbox", []),
104108
properties=item.get("properties", {}),
105109
links=item_links,
106-
assets=item.get("assets", {}),
110+
assets={a.pop("es_key"): a for a in item.get("assets", [])},
107111
)
108112

109113

@@ -128,6 +132,9 @@ def stac_to_db(
128132
collection["links"] = resolve_links(
129133
collection.get("links", []), str(request.base_url)
130134
)
135+
collection["assets"] = [
136+
{"es_key": k, **v} for k, v in collection.get("assets", {}).items()
137+
]
131138
return collection
132139

133140
@classmethod
@@ -174,5 +181,9 @@ def db_to_stac(
174181
collection_links += resolve_links(original_links, str(request.base_url))
175182
collection["links"] = collection_links
176183

184+
collection["assets"] = {
185+
a.pop("es_key"): a for a in collection.get("assets", [])
186+
}
187+
177188
# Return the stac_types.Collection object
178189
return stac_types.Collection(**collection)

stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/mappings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class Geometry(Protocol): # noqa
134134
"id": {"type": "keyword"},
135135
"collection": {"type": "keyword"},
136136
"geometry": {"type": "geo_shape"},
137-
"assets": {"type": "object", "enabled": False},
137+
"assets": {"type": "object"},
138138
"links": {"type": "object", "enabled": False},
139139
"properties": {
140140
"type": "object",

0 commit comments

Comments
 (0)