Skip to content

Commit f7bcff6

Browse files
author
Grzegorz Pustulka
committed
squash
1 parent 59d43f9 commit f7bcff6

File tree

36 files changed

+2515
-209
lines changed

36 files changed

+2515
-209
lines changed

.github/workflows/cicd.yml

Lines changed: 3 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

CHANGELOG.md

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

99
## [Unreleased]
1010

11+
### Added
12+
13+
- 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)
14+
- Added `ENABLE_DATETIME_INDEX_FILTERING` environment variable to enable datetime-based index selection using collection IDs. Requires indexes in format: `STAC_ITEMS_INDEX_PREFIX_collection-id_start_year-start_month-start_day-end_year-end_month-end_day`, e.g. `items_sentinel-2-l2a_2025-06-06-2025-09-22`. Default is `false`. [#405](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/405)
15+
- 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. 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)
16+
- Added search engine adapter system with support for both Elasticsearch and OpenSearch [#405](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/405):
17+
- `SearchEngineAdapter` base class with engine-specific implementations
18+
- `ElasticsearchAdapter` and `OpenSearchAdapter` with tailored index creation methods
19+
- Automatic engine type detection based on client class
20+
- `SearchEngineAdapterFactory` for creating appropriate adapters
21+
- Added datetime-based index selection strategies with caching support [#405](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/405):
22+
- `AsyncDatetimeBasedIndexSelector` and `SyncDatetimeBasedIndexSelector` for temporal filtering
23+
- `IndexCacheManager` with configurable TTL-based cache expiration (default 1 hour)
24+
- `AsyncIndexAliasLoader` and `SyncIndexAliasLoader` for alias management
25+
- `UnfilteredIndexSelector` as fallback for returning all available indexes
26+
- Added index insertion strategies with automatic partitioning [#405](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/405):
27+
- Simple insertion strategy (`AsyncSimpleIndexInserter`, `SyncSimpleIndexInserter`) for traditional single-index-per-collection approach
28+
- Datetime-based insertion strategy (`AsyncDatetimeIndexInserter`, `SyncDatetimeIndexInserter`) with time-based partitioning
29+
- Automatic index size monitoring and splitting when limits exceeded
30+
- Handling of chronologically early data and bulk operations
31+
- Added index management utilities [#405](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/405):
32+
- `IndexSizeManager` for size monitoring and overflow handling
33+
- `DatetimeIndexManager` for datetime-based index operations
34+
- Factory patterns (`IndexInsertionFactory`, `IndexSelectorFactory`) for strategy creation based on configuration
35+
36+
1137
## [v6.1.0] - 2025-07-24
1238

1339
### Added

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ test-opensearch:
7373

7474
.PHONY: test
7575
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'
76+
-$(run_es) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh elasticsearch:9200 && cd stac_fastapi/tests/ && pytest -s --cov=stac_fastapi --cov-report=term-missing'
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+
-$(run_os) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh opensearch:9202 && cd stac_fastapi/tests/ && pytest -s --cov=stac_fastapi --cov-report=term-missing'
8080
docker compose down
8181

8282
.PHONY: run-database-es

README.md

Lines changed: 25 additions & 24 deletions
Large diffs are not rendered by default.

compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ services:
7272
hostname: elasticsearch
7373
environment:
7474
ES_JAVA_OPTS: -Xms512m -Xmx1g
75+
action.destructive_requires_name: false
7576
volumes:
7677
- ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
7778
- ./elasticsearch/snapshots:/usr/share/elasticsearch/snapshots
@@ -86,6 +87,7 @@ services:
8687
- discovery.type=single-node
8788
- plugins.security.disabled=true
8889
- OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m
90+
- action.destructive_requires_name=false
8991
volumes:
9092
- ./opensearch/config/opensearch.yml:/usr/share/opensearch/config/opensearch.yml
9193
- ./opensearch/snapshots:/usr/share/opensearch/snapshots

stac_fastapi/core/stac_fastapi/core/core.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
BulkTransactionMethod,
3838
Items,
3939
)
40+
from stac_fastapi.sfeos_helpers.database import return_date
4041
from stac_fastapi.types import stac as stac_types
4142
from stac_fastapi.types.conformance import BASE_CONFORMANCE_CLASSES
4243
from stac_fastapi.types.core import AsyncBaseCoreClient
@@ -324,10 +325,16 @@ async def item_collection(
324325
search=search, collection_ids=[collection_id]
325326
)
326327

327-
if datetime:
328+
try:
329+
datetime_search = return_date(datetime)
328330
search = self.database.apply_datetime_filter(
329-
search=search, interval=datetime
331+
search=search, datetime_search=datetime_search
330332
)
333+
except (ValueError, TypeError) as e:
334+
# Handle invalid interval formats if return_date fails
335+
msg = f"Invalid interval format: {datetime}, error: {e}"
336+
logger.error(msg)
337+
raise HTTPException(status_code=400, detail=msg)
331338

332339
if bbox:
333340
bbox = [float(x) for x in bbox]
@@ -342,6 +349,7 @@ async def item_collection(
342349
sort=None,
343350
token=token,
344351
collection_ids=[collection_id],
352+
datetime_search=datetime_search,
345353
)
346354

347355
items = [
@@ -500,10 +508,16 @@ async def post_search(
500508
search=search, collection_ids=search_request.collections
501509
)
502510

503-
if search_request.datetime:
511+
try:
512+
datetime_search = return_date(search_request.datetime)
504513
search = self.database.apply_datetime_filter(
505-
search=search, interval=search_request.datetime
514+
search=search, datetime_search=datetime_search
506515
)
516+
except (ValueError, TypeError) as e:
517+
# Handle invalid interval formats if return_date fails
518+
msg = f"Invalid interval format: {search_request.datetime}, error: {e}"
519+
logger.error(msg)
520+
raise HTTPException(status_code=400, detail=msg)
507521

508522
if search_request.bbox:
509523
bbox = search_request.bbox
@@ -560,6 +574,7 @@ async def post_search(
560574
token=search_request.token,
561575
sort=sort,
562576
collection_ids=search_request.collections,
577+
datetime_search=datetime_search,
563578
)
564579

565580
fields = (

stac_fastapi/core/stac_fastapi/core/datetime_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utility functions to handle datetime parsing."""
2+
23
from datetime import datetime, timezone
34

45
from stac_fastapi.types.rfc3339 import rfc3339_str_to_datetime

stac_fastapi/core/stac_fastapi/core/serializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Serializers."""
2+
23
import abc
34
from copy import deepcopy
45
from typing import Any, List, Optional

stac_fastapi/core/stac_fastapi/core/session.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""database session management."""
2+
23
import logging
34

45
import attr

0 commit comments

Comments
 (0)