Skip to content

Commit 830e678

Browse files
authored
Merge pull request #168 from StijnCaerts/search-fields
Exclude unset fields in search response
2 parents 5f26c32 + 54186c6 commit 830e678

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313

1414
### Fixed
1515

16+
- Exclude unset fields in search response [#166](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/166)
1617

1718
## [v1.0.0]
1819

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,9 @@ async def post_search(
509509
filter_kwargs = search_request.fields.filter_fields
510510

511511
items = [
512-
orjson.loads(stac_pydantic.Item(**feat).json(**filter_kwargs))
512+
orjson.loads(
513+
stac_pydantic.Item(**feat).json(**filter_kwargs, exclude_unset=True)
514+
)
513515
for feat in items
514516
]
515517

stac_fastapi/elasticsearch/tests/api/test_api.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,23 @@ async def test_app_fields_extension_no_properties_post(app_client, ctx, txn_clie
163163
assert "properties" not in resp_json["features"][0]
164164

165165

166+
@pytest.mark.asyncio
167+
async def test_app_fields_extension_no_null_fields(app_client, ctx, txn_client):
168+
resp = await app_client.get("/search", params={"collections": ["test-collection"]})
169+
assert resp.status_code == 200
170+
resp_json = resp.json()
171+
# check if no null fields: https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/166
172+
for feature in resp_json["features"]:
173+
# assert "bbox" not in feature["geometry"]
174+
for link in feature["links"]:
175+
assert all(a not in link or link[a] is not None for a in ("title", "asset"))
176+
for asset in feature["assets"]:
177+
assert all(
178+
a not in asset or asset[a] is not None
179+
for a in ("start_datetime", "created")
180+
)
181+
182+
166183
@pytest.mark.asyncio
167184
async def test_app_fields_extension_return_all_properties(app_client, ctx, txn_client):
168185
item = ctx.item

0 commit comments

Comments
 (0)