Skip to content

Commit 2e81c7d

Browse files
authored
Merge branch 'main' into dependabot/github_actions/actions/checkout-5
2 parents fa765a8 + 8974c38 commit 2e81c7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2564
-282
lines changed

.github/workflows/cicd.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
xpack.security.enabled: false
2929
xpack.security.transport.ssl.enabled: false
3030
ES_JAVA_OPTS: -Xms512m -Xmx1g
31+
action.destructive_requires_name: false
3132
ports:
3233
- 9200:9200
3334

@@ -44,6 +45,7 @@ jobs:
4445
xpack.security.enabled: false
4546
xpack.security.transport.ssl.enabled: false
4647
ES_JAVA_OPTS: -Xms512m -Xmx1g
48+
action.destructive_requires_name: false
4749
ports:
4850
- 9400:9400
4951

@@ -60,6 +62,7 @@ jobs:
6062
plugins.security.disabled: true
6163
plugins.security.ssl.http.enabled: true
6264
OPENSEARCH_JAVA_OPTS: -Xms512m -Xmx512m
65+
action.destructive_requires_name: false
6366
ports:
6467
- 9202:9202
6568

@@ -120,5 +123,6 @@ jobs:
120123
ES_PORT: ${{ matrix.backend == 'elasticsearch7' && '9400' || matrix.backend == 'elasticsearch8' && '9200' || '9202' }}
121124
ES_HOST: 172.17.0.1
122125
ES_USE_SSL: false
126+
DATABASE_REFRESH: true
123127
ES_VERIFY_CERTS: false
124128
BACKEND: ${{ matrix.backend == 'elasticsearch7' && 'elasticsearch' || matrix.backend == 'elasticsearch8' && 'elasticsearch' || 'opensearch' }}

CHANGELOG.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,56 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88

99
## [Unreleased]
1010

11+
### Added
12+
13+
### Changed
14+
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+
17+
### Fixed
18+
19+
## [v6.2.1] - 2025-09-02
20+
21+
### Added
22+
23+
- 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)
24+
- 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)
25+
26+
### Changed
27+
28+
- 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)
29+
30+
## [v6.2.0] - 2025-08-27
31+
32+
### Added
33+
34+
- Added comprehensive index management system with dynamic selection and insertion strategies for improved performance and scalability [#405](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/405)
35+
- Added `ENABLE_DATETIME_INDEX_FILTERING` environment variable to enable datetime-based index selection using collection IDs. When enabled, the system creates indexes with UUID-based names and manages them through time-based aliases. Default is `false`. [#405](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/405)
36+
- Added `DATETIME_INDEX_MAX_SIZE_GB` environment variable to set maximum size limit in GB for datetime-based indexes. When an index exceeds this size, a new time-partitioned index will be created. Note: add +20% to target size due to ES/OS compression. Default is `25` GB. Only applies when `ENABLE_DATETIME_INDEX_FILTERING` is enabled. [#405](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/405)
37+
- Added index operations system with unified interface for both Elasticsearch and OpenSearch [#405](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/405):
38+
- `IndexOperations` class with common index creation and management methods
39+
- UUID-based physical index naming: `{prefix}_{collection-id}_{uuid4}`
40+
- Alias management: main collection alias, temporal aliases, and closed index aliases
41+
- Automatic alias updates when indexes reach size limits
42+
- Added datetime-based index selection strategies with caching support [#405](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/405):
43+
- `DatetimeBasedIndexSelector` for temporal filtering with intelligent caching
44+
- `IndexCacheManager` with configurable TTL-based cache expiration (default 1 hour)
45+
- `IndexAliasLoader` for alias management and cache refresh
46+
- `UnfilteredIndexSelector` as fallback for returning all available indexes
47+
- Added index insertion strategies with automatic partitioning [#405](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/405):
48+
- Simple insertion strategy (`SimpleIndexInserter`) for traditional single-index-per-collection approach
49+
- Datetime-based insertion strategy (`DatetimeIndexInserter`) with time-based partitioning
50+
- Automatic index size monitoring and splitting when limits exceeded
51+
- Handling of chronologically early data and bulk operations
52+
- Added index management utilities [#405](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/405):
53+
- `IndexSizeManager` for size monitoring and overflow handling with compression awareness
54+
- `DatetimeIndexManager` for datetime-based index operations and validation
55+
- Factory patterns (`IndexInsertionFactory`, `IndexSelectorFactory`) for strategy creation based on configuration
56+
57+
### Changed
58+
59+
- Added the Datetime-Based Index Management section to the Table of Contents in the readme, updating heading sizes to match the rest of the document [#418](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/418)
60+
1161
## [v6.1.0] - 2025-07-24
1262

1363
### Added
@@ -442,7 +492,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
442492
- Use genexp in execute_search and get_all_collections to return results.
443493
- Added db_to_stac serializer to item_collection method in core.py.
444494

445-
[Unreleased]: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/compare/v6.1.0...main
495+
[Unreleased]: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/compare/v6.2.1...main
496+
[v6.2.1]: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/compare/v6.2.0...v6.2.1
497+
[v6.2.0]: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/compare/v6.1.0...v6.2.0
446498
[v6.1.0]: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/compare/v6.0.0...v6.1.0
447499
[v6.0.0]: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/compare/v5.0.0...v6.0.0
448500
[v5.0.0]: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/compare/v4.2.0...v5.0.0

Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ run_os = docker compose \
2727
.PHONY: image-deploy-es
2828
image-deploy-es:
2929
docker build -f dockerfiles/Dockerfile.dev.es -t stac-fastapi-elasticsearch:latest .
30-
30+
3131
.PHONY: image-deploy-os
3232
image-deploy-os:
3333
docker build -f dockerfiles/Dockerfile.dev.os -t stac-fastapi-opensearch:latest .
@@ -71,14 +71,19 @@ test-opensearch:
7171
-$(run_os) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh opensearch:9202 && cd stac_fastapi/tests/ && pytest'
7272
docker compose down
7373

74-
.PHONY: test
75-
test:
76-
-$(run_es) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh elasticsearch:9200 && cd stac_fastapi/tests/ && pytest --cov=stac_fastapi --cov-report=term-missing'
74+
.PHONY: test-datetime-filtering-es
75+
test-datetime-filtering-es:
76+
-$(run_es) /bin/bash -c 'export ENABLE_DATETIME_INDEX_FILTERING=true && ./scripts/wait-for-it-es.sh elasticsearch:9200 && cd stac_fastapi/tests/ && pytest -s --cov=stac_fastapi --cov-report=term-missing -m datetime_filtering'
7777
docker compose down
7878

79-
-$(run_os) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh opensearch:9202 && cd stac_fastapi/tests/ && pytest --cov=stac_fastapi --cov-report=term-missing'
79+
.PHONY: test-datetime-filtering-os
80+
test-datetime-filtering-os:
81+
-$(run_os) /bin/bash -c 'export ENABLE_DATETIME_INDEX_FILTERING=true && ./scripts/wait-for-it-es.sh opensearch:9202 && cd stac_fastapi/tests/ && pytest -s --cov=stac_fastapi --cov-report=term-missing -m datetime_filtering'
8082
docker compose down
8183

84+
.PHONY: test
85+
test: test-elasticsearch test-datetime-filtering-es test-opensearch test-datetime-filtering-os
86+
8287
.PHONY: run-database-es
8388
run-database-es:
8489
docker compose run --rm elasticsearch

README.md

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ This project is built on the following technologies: STAC, stac-fastapi, FastAPI
8585
- [Auth](#auth)
8686
- [Aggregation](#aggregation)
8787
- [Rate Limiting](#rate-limiting)
88+
- [Datetime-Based Index Management](#datetime-based-index-management)
8889

8990
## Documentation & Resources
9091

@@ -226,10 +227,86 @@ You can customize additional settings in your `.env` file:
226227
| `RAISE_ON_BULK_ERROR` | Controls whether bulk insert operations raise exceptions on errors. If set to `true`, the operation will stop and raise an exception when an error occurs. If set to `false`, errors will be logged, and the operation will continue. **Note:** STAC Item and ItemCollection validation errors will always raise, regardless of this flag. | `false` | Optional |
227228
| `DATABASE_REFRESH` | Controls whether database operations refresh the index immediately after changes. If set to `true`, changes will be immediately searchable. If set to `false`, changes may not be immediately visible but can improve performance for bulk operations. If set to `wait_for`, changes will wait for the next refresh cycle to become visible. | `false` | Optional |
228229
| `ENABLE_TRANSACTIONS_EXTENSIONS` | Enables or disables the Transactions and Bulk Transactions API extensions. If set to `false`, the POST `/collections` route and related transaction endpoints (including bulk transaction operations) will be unavailable in the API. This is useful for deployments where mutating the catalog via the API should be prevented. | `true` | Optional |
230+
| `STAC_ITEM_LIMIT` | Sets the environment variable for result limiting to SFEOS for the number of returned items and STAC collections. | `10` | Optional |
229231

230232
> [!NOTE]
231233
> The variables `ES_HOST`, `ES_PORT`, `ES_USE_SSL`, `ES_VERIFY_CERTS` and `ES_TIMEOUT` apply to both Elasticsearch and OpenSearch backends, so there is no need to rename the key names to `OS_` even if you're using OpenSearch.
232234
235+
## Datetime-Based Index Management
236+
237+
### Overview
238+
239+
SFEOS supports two indexing strategies for managing STAC items:
240+
241+
1. **Simple Indexing** (default) - One index per collection
242+
2. **Datetime-Based Indexing** - Time-partitioned indexes with automatic management
243+
244+
The datetime-based indexing strategy is particularly useful for large temporal datasets. When a user provides a datetime parameter in a query, the system knows exactly which index to search, providing **multiple times faster searches** and significantly **reducing database load**.
245+
246+
### When to Use
247+
248+
**Recommended for:**
249+
- Systems with large collections containing millions of items
250+
- Systems requiring high-performance temporal searching
251+
252+
**Pros:**
253+
- Multiple times faster queries with datetime filter
254+
- Reduced database load - only relevant indexes are searched
255+
256+
**Cons:**
257+
- Slightly longer item indexing time (automatic index management)
258+
- Greater management complexity
259+
260+
### Configuration
261+
262+
#### Enabling Datetime-Based Indexing
263+
264+
Enable datetime-based indexing by setting the following environment variable:
265+
266+
```bash
267+
ENABLE_DATETIME_INDEX_FILTERING=true
268+
```
269+
270+
### Related Configuration Variables
271+
272+
| Variable | Description | Default | Example |
273+
|----------|-------------|---------|---------|
274+
| `ENABLE_DATETIME_INDEX_FILTERING` | Enables time-based index partitioning | `false` | `true` |
275+
| `DATETIME_INDEX_MAX_SIZE_GB` | Maximum size limit for datetime indexes (GB) - note: add +20% to target size due to ES/OS compression | `25` | `50` |
276+
| `STAC_ITEMS_INDEX_PREFIX` | Prefix for item indexes | `items_` | `stac_items_` |
277+
278+
## How Datetime-Based Indexing Works
279+
280+
### Index and Alias Naming Convention
281+
282+
The system uses a precise naming convention:
283+
284+
**Physical indexes:**
285+
```
286+
{ITEMS_INDEX_PREFIX}{collection-id}_{uuid4}
287+
```
288+
289+
**Aliases:**
290+
```
291+
{ITEMS_INDEX_PREFIX}{collection-id} # Main collection alias
292+
{ITEMS_INDEX_PREFIX}{collection-id}_{start-datetime} # Temporal alias
293+
{ITEMS_INDEX_PREFIX}{collection-id}_{start-datetime}_{end-datetime} # Closed index alias
294+
```
295+
296+
**Example:**
297+
298+
*Physical indexes:*
299+
- `items_sentinel-2-l2a_a1b2c3d4-e5f6-7890-abcd-ef1234567890`
300+
301+
*Aliases:*
302+
- `items_sentinel-2-l2a` - main collection alias
303+
- `items_sentinel-2-l2a_2024-01-01` - active alias from January 1, 2024
304+
- `items_sentinel-2-l2a_2024-01-01_2024-03-15` - closed index alias (reached size limit)
305+
306+
### Index Size Management
307+
308+
**Important - Data Compression:** Elasticsearch and OpenSearch automatically compress data. The configured `DATETIME_INDEX_MAX_SIZE_GB` limit refers to the compressed size on disk. It is recommended to add +20% to the target size to account for compression overhead and metadata.
309+
233310
## Interacting with the API
234311

235312
- **Creating a Collection**:
@@ -538,4 +615,3 @@ You can customize additional settings in your `.env` file:
538615
- Ensures fair resource allocation among all clients
539616
540617
- **Examples**: Implementation examples are available in the [examples/rate_limit](examples/rate_limit) directory.
541-

compose.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
environment:
1010
- STAC_FASTAPI_TITLE=stac-fastapi-elasticsearch
1111
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Elasticsearch backend
12-
- STAC_FASTAPI_VERSION=6.1.0
12+
- STAC_FASTAPI_VERSION=6.2.1
1313
- STAC_FASTAPI_LANDING_PAGE_ID=stac-fastapi-elasticsearch
1414
- APP_HOST=0.0.0.0
1515
- APP_PORT=8080
@@ -21,6 +21,7 @@ services:
2121
- ES_USE_SSL=false
2222
- ES_VERIFY_CERTS=false
2323
- BACKEND=elasticsearch
24+
- DATABASE_REFRESH=true
2425
ports:
2526
- "8080:8080"
2627
volumes:
@@ -42,7 +43,7 @@ services:
4243
environment:
4344
- STAC_FASTAPI_TITLE=stac-fastapi-opensearch
4445
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Opensearch backend
45-
- STAC_FASTAPI_VERSION=6.1.0
46+
- STAC_FASTAPI_VERSION=6.2.1
4647
- STAC_FASTAPI_LANDING_PAGE_ID=stac-fastapi-opensearch
4748
- APP_HOST=0.0.0.0
4849
- APP_PORT=8082
@@ -72,6 +73,7 @@ services:
7273
hostname: elasticsearch
7374
environment:
7475
ES_JAVA_OPTS: -Xms512m -Xmx1g
76+
action.destructive_requires_name: false
7577
volumes:
7678
- ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
7779
- ./elasticsearch/snapshots:/usr/share/elasticsearch/snapshots
@@ -86,6 +88,7 @@ services:
8688
- discovery.type=single-node
8789
- plugins.security.disabled=true
8890
- OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m
91+
- action.destructive_requires_name=false
8992
volumes:
9093
- ./opensearch/config/opensearch.yml:/usr/share/opensearch/config/opensearch.yml
9194
- ./opensearch/snapshots:/usr/share/opensearch/snapshots

examples/auth/compose.basic_auth.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
environment:
1010
- STAC_FASTAPI_TITLE=stac-fastapi-elasticsearch
1111
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Elasticsearch backend
12-
- STAC_FASTAPI_VERSION=6.1.0
12+
- STAC_FASTAPI_VERSION=6.2.1
1313
- STAC_FASTAPI_LANDING_PAGE_ID=stac-fastapi-elasticsearch
1414
- APP_HOST=0.0.0.0
1515
- APP_PORT=8080
@@ -43,7 +43,7 @@ services:
4343
environment:
4444
- STAC_FASTAPI_TITLE=stac-fastapi-opensearch
4545
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Opensearch backend
46-
- STAC_FASTAPI_VERSION=6.1.0
46+
- STAC_FASTAPI_VERSION=6.2.1
4747
- STAC_FASTAPI_LANDING_PAGE_ID=stac-fastapi-opensearch
4848
- APP_HOST=0.0.0.0
4949
- APP_PORT=8082

examples/auth/compose.oauth2.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
environment:
1010
- STAC_FASTAPI_TITLE=stac-fastapi-elasticsearch
1111
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Elasticsearch backend
12-
- STAC_FASTAPI_VERSION=6.1.0
12+
- STAC_FASTAPI_VERSION=6.2.1
1313
- STAC_FASTAPI_LANDING_PAGE_ID=stac-fastapi-elasticsearch
1414
- APP_HOST=0.0.0.0
1515
- APP_PORT=8080
@@ -44,7 +44,7 @@ services:
4444
environment:
4545
- STAC_FASTAPI_TITLE=stac-fastapi-opensearch
4646
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Opensearch backend
47-
- STAC_FASTAPI_VERSION=6.1.0
47+
- STAC_FASTAPI_VERSION=6.2.1
4848
- STAC_FASTAPI_LANDING_PAGE_ID=stac-fastapi-opensearch
4949
- APP_HOST=0.0.0.0
5050
- APP_PORT=8082

examples/auth/compose.route_dependencies.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
environment:
1010
- STAC_FASTAPI_TITLE=stac-fastapi-elasticsearch
1111
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Elasticsearch backend
12-
- STAC_FASTAPI_VERSION=6.1.0
12+
- STAC_FASTAPI_VERSION=6.2.1
1313
- STAC_FASTAPI_LANDING_PAGE_ID=stac-fastapi-elasticsearch
1414
- APP_HOST=0.0.0.0
1515
- APP_PORT=8080
@@ -43,7 +43,7 @@ services:
4343
environment:
4444
- STAC_FASTAPI_TITLE=stac-fastapi-opensearch
4545
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Opensearch backend
46-
- STAC_FASTAPI_VERSION=6.1.0
46+
- STAC_FASTAPI_VERSION=6.2.1
4747
- STAC_FASTAPI_LANDING_PAGE_ID=stac-fastapi-opensearch
4848
- APP_HOST=0.0.0.0
4949
- APP_PORT=8082

examples/rate_limit/compose.rate_limit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
environment:
1010
- STAC_FASTAPI_TITLE=stac-fastapi-elasticsearch
1111
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Elasticsearch backend
12-
- STAC_FASTAPI_VERSION=6.1.0
12+
- STAC_FASTAPI_VERSION=6.2.1
1313
- STAC_FASTAPI_LANDING_PAGE_ID=stac-fastapi-elasticsearch
1414
- APP_HOST=0.0.0.0
1515
- APP_PORT=8080
@@ -43,7 +43,7 @@ services:
4343
environment:
4444
- STAC_FASTAPI_TITLE=stac-fastapi-opensearch
4545
- STAC_FASTAPI_DESCRIPTION=A STAC FastAPI with an Opensearch backend
46-
- STAC_FASTAPI_VERSION=6.1.0
46+
- STAC_FASTAPI_VERSION=6.2.1
4747
- STAC_FASTAPI_LANDING_PAGE_ID=stac-fastapi-opensearch
4848
- APP_HOST=0.0.0.0
4949
- APP_PORT=8082

stac_fastapi/core/stac_fastapi/core/base_database_logic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ async def json_patch_item(
4848
item_id: str,
4949
operations: List,
5050
base_url: str,
51+
create_nest: bool = False,
5152
refresh: bool = True,
5253
) -> Dict:
5354
"""Patch a item in the database follows RF6902."""
@@ -94,6 +95,7 @@ async def json_patch_collection(
9495
collection_id: str,
9596
operations: List,
9697
base_url: str,
98+
create_nest: bool = False,
9799
refresh: bool = True,
98100
) -> Dict:
99101
"""Patch a collection in the database follows RF6902."""

0 commit comments

Comments
 (0)