diff --git a/CHANGELOG.md b/CHANGELOG.md index 77e74c57..6a31a37c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +- Added `id` field as secondary sort to sort config to ensure unique pagination tokens. [#421](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/421) +- Added default environment variable `STAC_ITEM_LIMIT` to SFEOS for result limiting of returned items and STAC collections [#419](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/419) + ### Changed - Simplified Patch class and updated patch script creation including adding nest creation for merge patch [#420](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/420) -- Added default environment variable `STAC_ITEM_LIMIT` to SFEOS for result limiting of returned items and STAC collections [#419](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/419) ## [v6.2.0] - 2025-08-27 diff --git a/stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/database/query.py b/stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/database/query.py index 97df5703..80d07128 100644 --- a/stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/database/query.py +++ b/stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/database/query.py @@ -80,11 +80,14 @@ def populate_sort_shared(sortby: List) -> Optional[Dict[str, Dict[str, str]]]: This function transforms a list of sort specifications into the format required by Elasticsearch/OpenSearch for sorting query results. The returned dictionary can be directly used in search requests. + Always includes 'id' as secondary sort to ensure unique pagination tokens. """ if sortby: - return {s.field: {"order": s.direction} for s in sortby} + sort_config = {s.field: {"order": s.direction} for s in sortby} + sort_config.setdefault("id", {"order": "asc"}) + return sort_config else: - return None + return {"id": {"order": "asc"}} def add_collections_to_body(