stac-fastapi-opensearch 6.5.1__py3-none-any.whl → 6.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,7 @@ from starlette.requests import Request
17
17
 
18
18
  from stac_fastapi.core.base_database_logic import BaseDatabaseLogic
19
19
  from stac_fastapi.core.serializers import CollectionSerializer, ItemSerializer
20
- from stac_fastapi.core.utilities import bbox2polygon, get_bool_env, get_max_limit
20
+ from stac_fastapi.core.utilities import MAX_LIMIT, bbox2polygon, get_bool_env
21
21
  from stac_fastapi.extensions.core.transaction.request import (
22
22
  PartialCollection,
23
23
  PartialItem,
@@ -29,6 +29,9 @@ from stac_fastapi.opensearch.config import (
29
29
  from stac_fastapi.opensearch.config import OpensearchSettings as SyncSearchSettings
30
30
  from stac_fastapi.sfeos_helpers import filter as filter_module
31
31
  from stac_fastapi.sfeos_helpers.database import (
32
+ add_bbox_shape_to_collection,
33
+ apply_collections_bbox_filter_shared,
34
+ apply_collections_datetime_filter_shared,
32
35
  apply_free_text_filter_shared,
33
36
  apply_intersects_filter_shared,
34
37
  create_index_templates_shared,
@@ -159,6 +162,7 @@ class DatabaseLogic(BaseDatabaseLogic):
159
162
  limit: int,
160
163
  request: Request,
161
164
  sort: Optional[List[Dict[str, Any]]] = None,
165
+ bbox: Optional[List[float]] = None,
162
166
  q: Optional[List[str]] = None,
163
167
  filter: Optional[Dict[str, Any]] = None,
164
168
  query: Optional[Dict[str, Dict[str, Any]]] = None,
@@ -171,6 +175,7 @@ class DatabaseLogic(BaseDatabaseLogic):
171
175
  limit (int): The number of results to return.
172
176
  request (Request): The FastAPI request object.
173
177
  sort (Optional[List[Dict[str, Any]]]): Optional sort parameter from the request.
178
+ bbox (Optional[List[float]]): Bounding box to filter collections by spatial extent.
174
179
  q (Optional[List[str]]): Free text search terms.
175
180
  query (Optional[Dict[str, Dict[str, Any]]]): Query extension parameters.
176
181
  filter (Optional[Dict[str, Any]]): Structured query in CQL2 format.
@@ -298,12 +303,15 @@ class DatabaseLogic(BaseDatabaseLogic):
298
303
  query_parts.append({"bool": {"must_not": {"match_all": {}}}})
299
304
  raise
300
305
 
301
- # Combine all query parts with AND logic if there are multiple
302
- datetime_filter = None
303
- if datetime:
304
- datetime_filter = self._apply_collection_datetime_filter(datetime)
305
- if datetime_filter:
306
- query_parts.append(datetime_filter)
306
+ # Apply bbox filter if provided
307
+ bbox_filter = apply_collections_bbox_filter_shared(bbox)
308
+ if bbox_filter:
309
+ query_parts.append(bbox_filter)
310
+
311
+ # Apply datetime filter if provided
312
+ datetime_filter = apply_collections_datetime_filter_shared(datetime)
313
+ if datetime_filter:
314
+ query_parts.append(datetime_filter)
307
315
 
308
316
  # Combine all query parts with AND logic
309
317
  if query_parts:
@@ -313,12 +321,6 @@ class DatabaseLogic(BaseDatabaseLogic):
313
321
  else {"bool": {"must": query_parts}}
314
322
  )
315
323
 
316
- # Create a copy of the body for count query (without pagination and sorting)
317
- count_body = body.copy()
318
- if "search_after" in count_body:
319
- del count_body["search_after"]
320
- count_body["size"] = 0
321
-
322
324
  # Create async tasks for both search and count
323
325
  search_task = asyncio.create_task(
324
326
  self.client.search(
@@ -454,41 +456,6 @@ class DatabaseLogic(BaseDatabaseLogic):
454
456
  search=search, free_text_queries=free_text_queries
455
457
  )
456
458
 
457
- @staticmethod
458
- def _apply_collection_datetime_filter(
459
- datetime_str: Optional[str],
460
- ) -> Optional[Dict[str, Any]]:
461
- """Create a temporal filter for collections based on their extent."""
462
- if not datetime_str:
463
- return None
464
-
465
- # Parse the datetime string into start and end
466
- if "/" in datetime_str:
467
- start, end = datetime_str.split("/")
468
- # Replace open-ended ranges with concrete dates
469
- if start == "..":
470
- # For open-ended start, use a very early date
471
- start = "1800-01-01T00:00:00Z"
472
- if end == "..":
473
- # For open-ended end, use a far future date
474
- end = "2999-12-31T23:59:59Z"
475
- else:
476
- # If it's just a single date, use it for both start and end
477
- start = end = datetime_str
478
-
479
- return {
480
- "bool": {
481
- "must": [
482
- # Check if any date in the array is less than or equal to the query end date
483
- # This will match if the collection's start date is before or equal to the query end date
484
- {"range": {"extent.temporal.interval": {"lte": end}}},
485
- # Check if any date in the array is greater than or equal to the query start date
486
- # This will match if the collection's end date is after or equal to the query start date
487
- {"range": {"extent.temporal.interval": {"gte": start}}},
488
- ]
489
- }
490
- }
491
-
492
459
  @staticmethod
493
460
  def apply_datetime_filter(
494
461
  search: Search, datetime: Optional[str]
@@ -808,7 +775,7 @@ class DatabaseLogic(BaseDatabaseLogic):
808
775
 
809
776
  search_body["sort"] = sort if sort else DEFAULT_SORT
810
777
 
811
- max_result_window = get_max_limit()
778
+ max_result_window = MAX_LIMIT
812
779
 
813
780
  size_limit = min(limit + 1, max_result_window)
814
781
 
@@ -1356,7 +1323,7 @@ class DatabaseLogic(BaseDatabaseLogic):
1356
1323
  ConflictError: If a Collection with the same id already exists in the database.
1357
1324
 
1358
1325
  Notes:
1359
- A new index is created for the items in the Collection using the `create_item_index` function.
1326
+ A new index is created for the items in the Collection if the index insertion strategy requires it.
1360
1327
  """
1361
1328
  collection_id = collection["id"]
1362
1329
 
@@ -1373,6 +1340,12 @@ class DatabaseLogic(BaseDatabaseLogic):
1373
1340
  if await self.client.exists(index=COLLECTIONS_INDEX, id=collection_id):
1374
1341
  raise ConflictError(f"Collection {collection_id} already exists")
1375
1342
 
1343
+ if get_bool_env("ENABLE_COLLECTIONS_SEARCH") or get_bool_env(
1344
+ "ENABLE_COLLECTIONS_SEARCH_ROUTE"
1345
+ ):
1346
+ # Convert bbox to bbox_shape for geospatial queries (ES/OS specific)
1347
+ add_bbox_shape_to_collection(collection)
1348
+
1376
1349
  await self.client.index(
1377
1350
  index=COLLECTIONS_INDEX,
1378
1351
  id=collection_id,
@@ -1464,6 +1437,12 @@ class DatabaseLogic(BaseDatabaseLogic):
1464
1437
  await self.delete_collection(collection_id=collection_id, **kwargs)
1465
1438
 
1466
1439
  else:
1440
+ if get_bool_env("ENABLE_COLLECTIONS_SEARCH") or get_bool_env(
1441
+ "ENABLE_COLLECTIONS_SEARCH_ROUTE"
1442
+ ):
1443
+ # Convert bbox to bbox_shape for geospatial queries (ES/OS specific)
1444
+ add_bbox_shape_to_collection(collection)
1445
+
1467
1446
  await self.client.index(
1468
1447
  index=COLLECTIONS_INDEX,
1469
1448
  id=collection_id,
@@ -1,2 +1,2 @@
1
1
  """library version."""
2
- __version__ = "6.5.1"
2
+ __version__ = "6.7.0"
@@ -0,0 +1,71 @@
1
+ Metadata-Version: 2.4
2
+ Name: stac_fastapi_opensearch
3
+ Version: 6.7.0
4
+ Summary: An implementation of STAC API based on the FastAPI framework with Opensearch.
5
+ Project-URL: Homepage, https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch
6
+ License: MIT
7
+ Keywords: FastAPI,Opensearch,STAC,STAC-API,stac-fastapi
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Intended Audience :: Information Technology
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Requires-Python: >=3.9
19
+ Requires-Dist: opensearch-py[async]~=2.8.0
20
+ Requires-Dist: opensearch-py~=2.8.0
21
+ Requires-Dist: sfeos-helpers==6.7.0
22
+ Requires-Dist: stac-fastapi-core==6.7.0
23
+ Requires-Dist: starlette<0.36.0,>=0.35.0
24
+ Requires-Dist: uvicorn~=0.23.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: ciso8601~=2.3.0; extra == 'dev'
27
+ Requires-Dist: httpx<0.28.0,>=0.24.0; extra == 'dev'
28
+ Requires-Dist: pre-commit~=3.0.0; extra == 'dev'
29
+ Requires-Dist: pytest-asyncio~=0.21.0; extra == 'dev'
30
+ Requires-Dist: pytest-cov~=4.0.0; extra == 'dev'
31
+ Requires-Dist: pytest~=8.0; extra == 'dev'
32
+ Provides-Extra: docs
33
+ Requires-Dist: mkdocs-material~=9.0.0; extra == 'docs'
34
+ Requires-Dist: mkdocs~=1.4.0; extra == 'docs'
35
+ Requires-Dist: pdocs~=1.2.0; extra == 'docs'
36
+ Provides-Extra: server
37
+ Requires-Dist: uvicorn[standard]~=0.23.0; extra == 'server'
38
+ Description-Content-Type: text/markdown
39
+
40
+ # stac-fastapi-opensearch
41
+
42
+ <p align="left">
43
+ <img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/sfeos.png" width=1000>
44
+ </p>
45
+
46
+ [![Downloads](https://static.pepy.tech/badge/stac-fastapi-core?color=blue)](https://pepy.tech/project/stac-fastapi-core)
47
+ [![GitHub contributors](https://img.shields.io/github/contributors/stac-utils/stac-fastapi-elasticsearch-opensearch?color=blue)](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/graphs/contributors)
48
+ [![GitHub stars](https://img.shields.io/github/stars/stac-utils/stac-fastapi-elasticsearch-opensearch.svg?color=blue)](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/stargazers)
49
+ [![GitHub forks](https://img.shields.io/github/forks/stac-utils/stac-fastapi-elasticsearch-opensearch.svg?color=blue)](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/network/members)
50
+ [![PyPI version](https://img.shields.io/pypi/v/stac-fastapi-elasticsearch.svg?color=blue)](https://pypi.org/project/stac-fastapi-elasticsearch/)
51
+ [![STAC](https://img.shields.io/badge/STAC-1.1.0-blue.svg)](https://github.com/radiantearth/stac-spec/tree/v1.1.0)
52
+ [![stac-fastapi](https://img.shields.io/badge/stac--fastapi-6.0.0-blue.svg)](https://github.com/stac-utils/stac-fastapi)
53
+
54
+ This is the OpenSearch backend for stac-fastapi. For full documentation, please see the [main README](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/blob/main/README.md).
55
+
56
+ ## Package Information
57
+
58
+ - **Package name**: stac-fastapi-opensearch
59
+ - **Description**: An implementation of STAC API based on the FastAPI framework with OpenSearch.
60
+ - **Documentation**: [https://stac-utils.github.io/stac-fastapi-elasticsearch-opensearch/](https://stac-utils.github.io/stac-fastapi-elasticsearch-opensearch/)
61
+ - **Source**: [GitHub Repository](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/)
62
+
63
+ ## Installation
64
+
65
+ ```bash
66
+ pip install stac-fastapi-opensearch
67
+ ```
68
+
69
+ ## Quick Start
70
+
71
+ For detailed usage and examples, please refer to the [main documentation](https://stac-utils.github.io/stac-fastapi-elasticsearch-opensearch/).
@@ -0,0 +1,9 @@
1
+ stac_fastapi/opensearch/__init__.py,sha256=iJWMUgn7mUvmuPQSO_FlyhJ5eDdbbfmGv1qnFOX5-qk,28
2
+ stac_fastapi/opensearch/app.py,sha256=paRSzdkT3yxkegC3KEg98CA7PpNQ0C2LW0Mozb_LcP0,10025
3
+ stac_fastapi/opensearch/config.py,sha256=zGx4-4c5zEnu_Bh8Ra3SkIC83tluDiz-wKYQclRRDJA,5179
4
+ stac_fastapi/opensearch/database_logic.py,sha256=JfqoMWl1K-d8QTmNi5MFp3ewZWU-q2AXyAHynrFKEKw,66932
5
+ stac_fastapi/opensearch/version.py,sha256=GMc7YzxyWeUVpr_RMVlweeoH2lCLxOWemF-FOkqKXx8,45
6
+ stac_fastapi_opensearch-6.7.0.dist-info/METADATA,sha256=9Sqwazl1g0T1Xjtg67yko9xr4CXYyV_GjEmjhBFY_iY,3855
7
+ stac_fastapi_opensearch-6.7.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ stac_fastapi_opensearch-6.7.0.dist-info/entry_points.txt,sha256=zjZ0Xsr9BUNJqMkdPpl6zEIUykv1uFdJtNELFRChp0w,76
9
+ stac_fastapi_opensearch-6.7.0.dist-info/RECORD,,
@@ -1,5 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.45.1)
2
+ Generator: hatchling 1.27.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
-
@@ -1,732 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: stac-fastapi-opensearch
3
- Version: 6.5.1
4
- Summary: Opensearch stac-fastapi backend.
5
- Home-page: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch
6
- License: MIT
7
- Classifier: Intended Audience :: Developers
8
- Classifier: Intended Audience :: Information Technology
9
- Classifier: Intended Audience :: Science/Research
10
- Classifier: Programming Language :: Python :: 3.9
11
- Classifier: Programming Language :: Python :: 3.10
12
- Classifier: Programming Language :: Python :: 3.11
13
- Classifier: Programming Language :: Python :: 3.12
14
- Classifier: Programming Language :: Python :: 3.13
15
- Classifier: License :: OSI Approved :: MIT License
16
- Requires-Python: >=3.9
17
- Description-Content-Type: text/markdown
18
- Requires-Dist: stac-fastapi-core==6.5.1
19
- Requires-Dist: sfeos-helpers==6.5.1
20
- Requires-Dist: opensearch-py~=2.8.0
21
- Requires-Dist: opensearch-py[async]~=2.8.0
22
- Requires-Dist: uvicorn~=0.23.0
23
- Requires-Dist: starlette<0.36.0,>=0.35.0
24
- Provides-Extra: dev
25
- Requires-Dist: pytest~=7.0.0; extra == "dev"
26
- Requires-Dist: pytest-cov~=4.0.0; extra == "dev"
27
- Requires-Dist: pytest-asyncio~=0.21.0; extra == "dev"
28
- Requires-Dist: pre-commit~=3.0.0; extra == "dev"
29
- Requires-Dist: ciso8601~=2.3.0; extra == "dev"
30
- Requires-Dist: httpx<0.28.0,>=0.24.0; extra == "dev"
31
- Provides-Extra: docs
32
- Requires-Dist: mkdocs~=1.4.0; extra == "docs"
33
- Requires-Dist: mkdocs-material~=9.0.0; extra == "docs"
34
- Requires-Dist: pdocs~=1.2.0; extra == "docs"
35
- Provides-Extra: server
36
- Requires-Dist: uvicorn[standard]~=0.23.0; extra == "server"
37
-
38
- # stac-fastapi-elasticsearch-opensearch
39
-
40
- <!-- markdownlint-disable MD033 MD041 -->
41
-
42
-
43
- <p align="left">
44
- <img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/sfeos.png" width=1000>
45
- </p>
46
-
47
- **Jump to:** [Project Introduction](#project-introduction---what-is-sfeos) | [Quick Start](#quick-start) | [Table of Contents](#table-of-contents)
48
-
49
- [![Downloads](https://static.pepy.tech/badge/stac-fastapi-core?color=blue)](https://pepy.tech/project/stac-fastapi-core)
50
- [![GitHub contributors](https://img.shields.io/github/contributors/stac-utils/stac-fastapi-elasticsearch-opensearch?color=blue)](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/graphs/contributors)
51
- [![GitHub stars](https://img.shields.io/github/stars/stac-utils/stac-fastapi-elasticsearch-opensearch.svg?color=blue)](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/stargazers)
52
- [![GitHub forks](https://img.shields.io/github/forks/stac-utils/stac-fastapi-elasticsearch-opensearch.svg?color=blue)](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/network/members)
53
- [![PyPI version](https://img.shields.io/pypi/v/stac-fastapi-elasticsearch.svg?color=blue)](https://pypi.org/project/stac-fastapi-elasticsearch/)
54
- [![STAC](https://img.shields.io/badge/STAC-1.1.0-blue.svg)](https://github.com/radiantearth/stac-spec/tree/v1.1.0)
55
- [![stac-fastapi](https://img.shields.io/badge/stac--fastapi-6.0.0-blue.svg)](https://github.com/stac-utils/stac-fastapi)
56
-
57
- ## Sponsors & Supporters
58
-
59
- The following organizations have contributed time and/or funding to support the development of this project:
60
-
61
- <p align="left">
62
- <a href="https://healy-hyperspatial.github.io/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/hh-logo-blue.png" alt="Healy Hyperspatial" height="100" hspace="20"></a>
63
- <a href="https://atomicmaps.io/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/am-logo-black.png" alt="Atomic Maps" height="100" hspace="20"></a>
64
- <a href="https://remotesensing.vito.be/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/VITO.png" alt="VITO Remote Sensing" height="100" hspace="20"></a>
65
- </p>
66
-
67
- ## Project Introduction - What is SFEOS?
68
-
69
- SFEOS (stac-fastapi-elasticsearch-opensearch) is a high-performance, scalable API implementation for serving SpatioTemporal Asset Catalog (STAC) data - an enhanced GeoJSON format designed specifically for geospatial assets like satellite imagery, aerial photography, and other Earth observation data. This project enables organizations to:
70
-
71
- - **Efficiently catalog and search geospatial data** such as satellite imagery, aerial photography, DEMs, and other geospatial assets using Elasticsearch or OpenSearch as the database backend
72
- - **Implement standardized STAC APIs** that support complex spatial, temporal, and property-based queries across large collections of geospatial data
73
- - **Scale to millions of geospatial assets** with fast search performance through optimized spatial indexing and query capabilities
74
- - **Support OGC-compliant filtering** including spatial operations (intersects, contains, etc.) and temporal queries
75
- - **Perform geospatial aggregations** to analyze data distribution across space and time
76
- - **Enhanced collection search capabilities** with support for sorting and field selection
77
-
78
- This implementation builds on the STAC-FastAPI framework, providing a production-ready solution specifically optimized for Elasticsearch and OpenSearch databases. It's ideal for organizations managing large geospatial data catalogs who need efficient discovery and access capabilities through standardized APIs.
79
-
80
- ## Common Deployment Patterns
81
-
82
- stac-fastapi-elasticsearch-opensearch can be deployed in several ways depending on your needs:
83
-
84
- - **Containerized Application**: Run as a Docker container with connections to Elasticsearch/OpenSearch databases
85
- - **Serverless Function**: Deploy as AWS Lambda or similar serverless function with API Gateway
86
- - **Traditional Server**: Run on virtual machines or bare metal servers in your infrastructure
87
- - **Kubernetes**: Deploy as part of a larger microservices architecture with container orchestration
88
-
89
- The implementation is flexible and can scale from small local deployments to large production environments serving millions of geospatial assets.
90
-
91
- ## Technologies
92
-
93
- This project is built on the following technologies: STAC, stac-fastapi, FastAPI, Elasticsearch, Python, OpenSearch
94
-
95
- <p align="left">
96
- <a href="https://stacspec.org/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/STAC-01.png" alt="STAC" height="100" hspace="10"></a>
97
- <a href="https://www.python.org/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/python.png" alt="Python" height="80" hspace="10"></a>
98
- <a href="https://fastapi.tiangolo.com/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/fastapi.svg" alt="FastAPI" height="80" hspace="10"></a>
99
- <a href="https://www.elastic.co/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/elasticsearch.png" alt="Elasticsearch" height="80" hspace="10"></a>
100
- <a href="https://opensearch.org/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/opensearch.svg" alt="OpenSearch" height="80" hspace="10"></a>
101
- </p>
102
-
103
- ## Table of Contents
104
-
105
- - [stac-fastapi-elasticsearch-opensearch](#stac-fastapi-elasticsearch-opensearch)
106
- - [Sponsors & Supporters](#sponsors--supporters)
107
- - [Project Introduction - What is SFEOS?](#project-introduction---what-is-sfeos)
108
- - [Common Deployment Patterns](#common-deployment-patterns)
109
- - [Technologies](#technologies)
110
- - [Table of Contents](#table-of-contents)
111
- - [Collection Search Extensions](#collection-search-extensions)
112
- - [Documentation & Resources](#documentation--resources)
113
- - [Package Structure](#package-structure)
114
- - [Examples](#examples)
115
- - [Performance](#performance)
116
- - [Direct Response Mode](#direct-response-mode)
117
- - [Quick Start](#quick-start)
118
- - [Installation](#installation)
119
- - [Running Locally](#running-locally)
120
- - [Using Pre-built Docker Images](#using-pre-built-docker-images)
121
- - [Using Docker Compose](#using-docker-compose)
122
- - [Configuration Reference](#configuration-reference)
123
- - [Datetime-Based Index Management](#datetime-based-index-management)
124
- - [Overview](#overview)
125
- - [When to Use](#when-to-use)
126
- - [Configuration](#configuration)
127
- - [Enabling Datetime-Based Indexing](#enabling-datetime-based-indexing)
128
- - [Related Configuration Variables](#related-configuration-variables)
129
- - [How Datetime-Based Indexing Works](#how-datetime-based-indexing-works)
130
- - [Index and Alias Naming Convention](#index-and-alias-naming-convention)
131
- - [Index Size Management](#index-size-management)
132
- - [Interacting with the API](#interacting-with-the-api)
133
- - [Configure the API](#configure-the-api)
134
- - [Collection Pagination](#collection-pagination)
135
- - [Ingesting Sample Data CLI Tool](#ingesting-sample-data-cli-tool)
136
- - [Elasticsearch Mappings](#elasticsearch-mappings)
137
- - [Managing Elasticsearch Indices](#managing-elasticsearch-indices)
138
- - [Snapshots](#snapshots)
139
- - [Reindexing](#reindexing)
140
- - [Auth](#auth)
141
- - [Aggregation](#aggregation)
142
- - [Rate Limiting](#rate-limiting)
143
-
144
- ## Documentation & Resources
145
-
146
- - **Online Documentation**: [https://stac-utils.github.io/stac-fastapi-elasticsearch-opensearch](https://stac-utils.github.io/stac-fastapi-elasticsearch-opensearch/)
147
- - **Source Code**: [https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch)
148
- - **API Examples**: [Postman Documentation](https://documenter.getpostman.com/view/12888943/2s8ZDSdRHA) - Examples of how to use the API endpoints
149
- - **Community**:
150
- - [Gitter Chat](https://app.gitter.im/#/room/#stac-fastapi-elasticsearch_community:gitter.im) - For real-time discussions
151
- - [GitHub Discussions](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/discussions) - For longer-form questions and answers
152
-
153
- ## Collection Search Extensions
154
-
155
- SFEOS provides enhanced collection search capabilities through two primary routes:
156
- - **GET/POST `/collections`**: The standard STAC endpoint with extended query parameters
157
- - **GET/POST `/collections-search`**: A custom endpoint that supports the same parameters, created to avoid conflicts with the STAC Transactions extension if enabled (which uses POST `/collections` for collection creation)
158
-
159
- These endpoints support advanced collection discovery features including:
160
-
161
- - **Sorting**: Sort collections by sortable fields using the `sortby` parameter
162
- - Example: `/collections?sortby=+id` (ascending sort by ID)
163
- - Example: `/collections?sortby=-id` (descending sort by ID)
164
- - Example: `/collections?sortby=-temporal` (descending sort by temporal extent)
165
-
166
- - **Field Selection**: Request only specific fields to be returned using the `fields` parameter
167
- - Example: `/collections?fields=id,title,description`
168
- - This helps reduce payload size when only certain fields are needed
169
-
170
- - **Free Text Search**: Search across collection text fields using the `q` parameter
171
- - Example: `/collections?q=landsat`
172
- - Searches across multiple text fields including title, description, and keywords
173
- - Supports partial word matching and relevance-based sorting
174
-
175
- - **Structured Filtering**: Filter collections using CQL2 expressions
176
- - JSON format: `/collections?filter={"op":"=","args":[{"property":"id"},"sentinel-2"]}&filter-lang=cql2-json`
177
- - Text format: `/collections?filter=id='sentinel-2'&filter-lang=cql2-text` (note: string values must be quoted)
178
- - Advanced text format: `/collections?filter=id LIKE '%sentinel%'&filter-lang=cql2-text` (supports LIKE, BETWEEN, etc.)
179
- - Supports both CQL2 JSON and CQL2 text formats with various operators
180
- - Enables precise filtering on any collection property
181
-
182
- - **Datetime Filtering**: Filter collections by their temporal extent using the `datetime` parameter
183
- - Example: `/collections?datetime=2020-01-01T00:00:00Z/2020-12-31T23:59:59Z` (finds collections with temporal extents that overlap this range)
184
- - Example: `/collections?datetime=2020-06-15T12:00:00Z` (finds collections whose temporal extent includes this specific time)
185
- - Example: `/collections?datetime=2020-01-01T00:00:00Z/..` (finds collections with temporal extents that extend to or beyond January 1, 2020)
186
- - Example: `/collections?datetime=../2020-12-31T23:59:59Z` (finds collections with temporal extents that begin on or before December 31, 2020)
187
- - Collections are matched if their temporal extent overlaps with the provided datetime parameter
188
- - This allows for efficient discovery of collections based on time periods
189
-
190
- These extensions make it easier to build user interfaces that display and navigate through collections efficiently.
191
-
192
- > **Configuration**: Collection search extensions (sorting, field selection, free text search, structured filtering, and datetime filtering) for the `/collections` endpoint can be disabled by setting the `ENABLE_COLLECTIONS_SEARCH` environment variable to `false`. By default, these extensions are enabled.
193
- >
194
- > **Configuration**: The custom `/collections-search` endpoint can be enabled by setting the `ENABLE_COLLECTIONS_SEARCH_ROUTE` environment variable to `true`. By default, this endpoint is **disabled**.
195
-
196
- > **Note**: Sorting is only available on fields that are indexed for sorting in Elasticsearch/OpenSearch. With the default mappings, you can sort on:
197
- > - `id` (keyword field)
198
- > - `extent.temporal.interval` (date field)
199
- > - `temporal` (alias to extent.temporal.interval)
200
- >
201
- > Text fields like `title` and `description` are not sortable by default as they use text analysis for better search capabilities. Attempting to sort on these fields will result in a user-friendly error message explaining which fields are sortable and how to make additional fields sortable by updating the mappings.
202
- >
203
- > **Important**: Adding keyword fields to make text fields sortable can significantly increase the index size, especially for large text fields. Consider the storage implications when deciding which fields to make sortable.
204
-
205
-
206
- ## Package Structure
207
-
208
- This project is organized into several packages, each with a specific purpose:
209
-
210
- - **stac_fastapi_core**: Core functionality that's database-agnostic, including API models, extensions, and shared utilities. This package provides the foundation for building STAC API implementations with any database backend. See [stac-fastapi-mongo](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo) for a working example.
211
-
212
- - **sfeos_helpers**: Shared helper functions and utilities used by both the Elasticsearch and OpenSearch backends. This package includes:
213
- - `database`: Specialized modules for index, document, and database utility operations
214
- - `aggregation`: Elasticsearch/OpenSearch-specific aggregation functionality
215
- - Shared logic and utilities that improve code reuse between backends
216
-
217
- - **stac_fastapi_elasticsearch**: Complete implementation of the STAC API using Elasticsearch as the backend database. This package depends on both `stac_fastapi_core` and `sfeos_helpers`.
218
-
219
- - **stac_fastapi_opensearch**: Complete implementation of the STAC API using OpenSearch as the backend database. This package depends on both `stac_fastapi_core` and `sfeos_helpers`.
220
-
221
- ## Examples
222
-
223
- The `/examples` directory contains several useful examples and reference implementations:
224
-
225
- - **pip_docker**: Examples of running stac-fastapi-elasticsearch from PyPI in Docker without needing any code from the repository
226
- - **auth**: Authentication examples including:
227
- - Basic authentication
228
- - OAuth2 with Keycloak
229
- - Route dependencies configuration
230
- - **rate_limit**: Example of implementing rate limiting for API requests
231
- - **postman_collections**: Postman collection files you can import for testing API endpoints
232
-
233
- These examples provide practical reference implementations for various deployment scenarios and features.
234
-
235
- ## Performance
236
-
237
- ### Direct Response Mode
238
-
239
- - The `enable_direct_response` option is provided by the stac-fastapi core library (introduced in stac-fastapi 5.2.0) and is available in this project starting from v4.0.0.
240
- - **Control via environment variable**: Set `ENABLE_DIRECT_RESPONSE=true` to enable this feature.
241
- - **How it works**: When enabled, endpoints return Starlette Response objects directly, bypassing FastAPI's default serialization for improved performance.
242
- - **Important limitation**: All FastAPI dependencies (including authentication, custom status codes, and validation) are disabled for all routes when this mode is enabled.
243
- - **Best use case**: This mode is best suited for public or read-only APIs where authentication and custom logic are not required.
244
- - **Default setting**: `false` for safety.
245
- - **More information**: See [issue #347](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/issues/347) for background and implementation details.
246
-
247
- ## Quick Start
248
-
249
- This section helps you get up and running with stac-fastapi-elasticsearch-opensearch quickly.
250
-
251
- ### Installation
252
-
253
- - **For versions 4.0.0a1 and newer** (PEP 625 compliant naming):
254
- ```bash
255
- pip install stac-fastapi-elasticsearch # Elasticsearch backend
256
- pip install stac-fastapi-opensearch # Opensearch backend
257
- pip install stac-fastapi-core # Core library
258
- ```
259
-
260
- - **For versions 4.0.0a0 and older**:
261
- ```bash
262
- pip install stac-fastapi.elasticsearch # Elasticsearch backend
263
- pip install stac-fastapi.opensearch # Opensearch backend
264
- pip install stac-fastapi.core # Core library
265
- ```
266
-
267
- > **Important Note:** Starting with version 4.0.0a1, package names have changed from using periods (e.g., `stac-fastapi.core`) to using hyphens (e.g., `stac-fastapi-core`) to comply with PEP 625. The internal package structure uses underscores, but users should install with hyphens as shown above. Please update your requirements files accordingly.
268
-
269
- ### Running Locally
270
-
271
- There are two main ways to run the API locally:
272
-
273
- #### Using Pre-built Docker Images
274
-
275
- - We provide ready-to-use Docker images through GitHub Container Registry:
276
- - [ElasticSearch backend](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pkgs/container/stac-fastapi-es)
277
- - [OpenSearch backend](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pkgs/container/stac-fastapi-os)
278
-
279
- - **Pull and run the images**:
280
- ```shell
281
- # For Elasticsearch backend
282
- docker pull ghcr.io/stac-utils/stac-fastapi-es:latest
283
-
284
- # For OpenSearch backend
285
- docker pull ghcr.io/stac-utils/stac-fastapi-os:latest
286
- ```
287
-
288
- #### Using Docker Compose
289
-
290
- - **Prerequisites**: Ensure [Docker Compose](https://docs.docker.com/compose/install/) or [Podman Compose](https://podman-desktop.io/docs/compose) is installed on your machine.
291
-
292
- - **Start the API**:
293
- ```shell
294
- docker compose up elasticsearch app-elasticsearch
295
- ```
296
-
297
- - **Configuration**: By default, Docker Compose uses Elasticsearch 8.x and OpenSearch 2.11.1. To use different versions, create a `.env` file:
298
- ```shell
299
- ELASTICSEARCH_VERSION=8.11.0
300
- OPENSEARCH_VERSION=2.11.1
301
- ENABLE_DIRECT_RESPONSE=false
302
- ```
303
-
304
- - **Compatibility**: The most recent Elasticsearch 7.x versions should also work. See the [opensearch-py docs](https://github.com/opensearch-project/opensearch-py/blob/main/COMPATIBILITY.md) for compatibility information.
305
-
306
-
307
-
308
- ## Configuration Reference
309
-
310
- You can customize additional settings in your `.env` file:
311
-
312
- | Variable | Description | Default | Required |
313
- |------------------------------|--------------------------------------------------------------------------------------|--------------------------|---------------------------------------------------------------------------------------------|
314
- | `ES_HOST` | Hostname for external Elasticsearch/OpenSearch. | `localhost` | Optional |
315
- | `ES_PORT` | Port for Elasticsearch/OpenSearch. | `9200` (ES) / `9202` (OS)| Optional |
316
- | `ES_USE_SSL` | Use SSL for connecting to Elasticsearch/OpenSearch. | `true` | Optional |
317
- | `ES_VERIFY_CERTS` | Verify SSL certificates when connecting. | `true` | Optional |
318
- | `ES_API_KEY` | API Key for external Elasticsearch/OpenSearch. | N/A | Optional |
319
- | `ES_TIMEOUT` | Client timeout for Elasticsearch/OpenSearch. | DB client default | Optional |
320
- | `STAC_FASTAPI_TITLE` | Title of the API in the documentation. | `stac-fastapi-<backend>` | Optional |
321
- | `STAC_FASTAPI_DESCRIPTION` | Description of the API in the documentation. | N/A | Optional |
322
- | `STAC_FASTAPI_VERSION` | API version. | `2.1` | Optional |
323
- | `STAC_FASTAPI_LANDING_PAGE_ID` | Landing page ID | `stac-fastapi` | Optional |
324
- | `APP_HOST` | Server bind address. | `0.0.0.0` | Optional |
325
- | `APP_PORT` | Server port. | `8000` | Optional |
326
- | `ENVIRONMENT` | Runtime environment. | `local` | Optional |
327
- | `WEB_CONCURRENCY` | Number of worker processes. | `10` | Optional |
328
- | `RELOAD` | Enable auto-reload for development. | `true` | Optional |
329
- | `STAC_FASTAPI_RATE_LIMIT` | API rate limit per client. | `200/minute` | Optional |
330
- | `BACKEND` | Tests-related variable | `elasticsearch` or `opensearch` based on the backend | Optional |
331
- | `ELASTICSEARCH_VERSION` | Version of Elasticsearch to use. | `8.11.0` | Optional |
332
- | `OPENSEARCH_VERSION` | OpenSearch version | `2.11.1` | Optional |
333
- | `ENABLE_DIRECT_RESPONSE` | Enable direct response for maximum performance (disables all FastAPI dependencies, including authentication, custom status codes, and validation) | `false` | Optional |
334
- | `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 |
335
- | `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 |
336
- | `ENABLE_COLLECTIONS_SEARCH` | Enable collection search extensions (sort, fields, free text search, structured filtering, and datetime filtering) on the core `/collections` endpoint. | `true` | Optional |
337
- | `ENABLE_COLLECTIONS_SEARCH_ROUTE` | Enable the custom `/collections-search` endpoint (both GET and POST methods). When disabled, the custom endpoint will not be available, but collection search extensions will still be available on the core `/collections` endpoint if `ENABLE_COLLECTIONS_SEARCH` is true. | `false` | Optional |
338
- | `ENABLE_TRANSACTIONS_EXTENSIONS` | Enables or disables the Transactions and Bulk Transactions API extensions. This is useful for deployments where mutating the catalog via the API should be prevented. If set to `true`, the POST `/collections` route for search will be unavailable in the API. | `true` | Optional |
339
- | `STAC_ITEM_LIMIT` | Sets the environment variable for result limiting to SFEOS for the number of returned items and STAC collections. | `10` | Optional |
340
- | `STAC_INDEX_ASSETS` | Controls if Assets are indexed when added to Elasticsearch/Opensearch. This allows asset fields to be included in search queries. | `false` | Optional |
341
- | `ENV_MAX_LIMIT` | Configures the environment variable in SFEOS to override the default `MAX_LIMIT`, which controls the limit parameter for returned items and STAC collections. | `10,000` | Optional |
342
- | `USE_DATETIME` | Configures the datetime search behavior in SFEOS. When enabled, searches both datetime field and falls back to start_datetime/end_datetime range for items with null datetime. When disabled, searches only by start_datetime/end_datetime range. | `true` | Optional |
343
-
344
- > [!NOTE]
345
- > 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.
346
-
347
- ## Datetime-Based Index Management
348
-
349
- ### Overview
350
-
351
- SFEOS supports two indexing strategies for managing STAC items:
352
-
353
- 1. **Simple Indexing** (default) - One index per collection
354
- 2. **Datetime-Based Indexing** - Time-partitioned indexes with automatic management
355
-
356
- 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**.
357
-
358
- ### When to Use
359
-
360
- **Recommended for:**
361
- - Systems with large collections containing millions of items
362
- - Systems requiring high-performance temporal searching
363
-
364
- **Pros:**
365
- - Multiple times faster queries with datetime filter
366
- - Reduced database load - only relevant indexes are searched
367
-
368
- **Cons:**
369
- - Slightly longer item indexing time (automatic index management)
370
- - Greater management complexity
371
-
372
- ### Configuration
373
-
374
- #### Enabling Datetime-Based Indexing
375
-
376
- Enable datetime-based indexing by setting the following environment variable:
377
-
378
- ```bash
379
- ENABLE_DATETIME_INDEX_FILTERING=true
380
- ```
381
-
382
- ### Related Configuration Variables
383
-
384
- | Variable | Description | Default | Example |
385
- |----------|-------------|---------|---------|
386
- | `ENABLE_DATETIME_INDEX_FILTERING` | Enables time-based index partitioning | `false` | `true` |
387
- | `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` |
388
- | `STAC_ITEMS_INDEX_PREFIX` | Prefix for item indexes | `items_` | `stac_items_` |
389
-
390
- ## How Datetime-Based Indexing Works
391
-
392
- ### Index and Alias Naming Convention
393
-
394
- The system uses a precise naming convention:
395
-
396
- **Physical indexes:**
397
- ```
398
- {ITEMS_INDEX_PREFIX}{collection-id}_{uuid4}
399
- ```
400
-
401
- **Aliases:**
402
- ```
403
- {ITEMS_INDEX_PREFIX}{collection-id} # Main collection alias
404
- {ITEMS_INDEX_PREFIX}{collection-id}_{start-datetime} # Temporal alias
405
- {ITEMS_INDEX_PREFIX}{collection-id}_{start-datetime}_{end-datetime} # Closed index alias
406
- ```
407
-
408
- **Example:**
409
-
410
- *Physical indexes:*
411
- - `items_sentinel-2-l2a_a1b2c3d4-e5f6-7890-abcd-ef1234567890`
412
-
413
- *Aliases:*
414
- - `items_sentinel-2-l2a` - main collection alias
415
- - `items_sentinel-2-l2a_2024-01-01` - active alias from January 1, 2024
416
- - `items_sentinel-2-l2a_2024-01-01_2024-03-15` - closed index alias (reached size limit)
417
-
418
- ### Index Size Management
419
-
420
- **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.
421
-
422
- ## Interacting with the API
423
-
424
- - **Creating a Collection**:
425
- ```shell
426
- curl -X "POST" "http://localhost:8080/collections" \
427
- -H 'Content-Type: application/json; charset=utf-8' \
428
- -d $'{
429
- "id": "my_collection"
430
- }'
431
- ```
432
-
433
- - **Adding an Item to a Collection**:
434
- ```shell
435
- curl -X "POST" "http://localhost:8080/collections/my_collection/items" \
436
- -H 'Content-Type: application/json; charset=utf-8' \
437
- -d @item.json
438
- ```
439
-
440
- - **Searching for Items**:
441
- ```shell
442
- curl -X "GET" "http://localhost:8080/search" \
443
- -H 'Content-Type: application/json; charset=utf-8' \
444
- -d $'{
445
- "collections": ["my_collection"],
446
- "limit": 10
447
- }'
448
- ```
449
-
450
- - **Filtering by Bbox**:
451
- ```shell
452
- curl -X "GET" "http://localhost:8080/search" \
453
- -H 'Content-Type: application/json; charset=utf-8' \
454
- -d $'{
455
- "collections": ["my_collection"],
456
- "bbox": [-180, -90, 180, 90]
457
- }'
458
- ```
459
-
460
- - **Filtering by Datetime**:
461
- ```shell
462
- curl -X "GET" "http://localhost:8080/search" \
463
- -H 'Content-Type: application/json; charset=utf-8' \
464
- -d $'{
465
- "collections": ["my_collection"],
466
- "datetime": "2020-01-01T00:00:00Z/2020-12-31T23:59:59Z"
467
- }'
468
- ```
469
-
470
- ## Configure the API
471
-
472
- - **API Title and Description**: By default set to `stac-fastapi-<backend>`. Customize these by setting:
473
- - `STAC_FASTAPI_TITLE`: Changes the API title in the documentation
474
- - `STAC_FASTAPI_DESCRIPTION`: Changes the API description in the documentation
475
-
476
- - **Database Indices**: By default, the API reads from and writes to:
477
- - `collections` index for collections
478
- - `items_<collection name>` indices for items
479
- - Customize with `STAC_COLLECTIONS_INDEX` and `STAC_ITEMS_INDEX_PREFIX` environment variables
480
-
481
- - **Root Path Configuration**: The application root path is the base URL by default.
482
- - For AWS Lambda with Gateway API: Set `STAC_FASTAPI_ROOT_PATH` to match the Gateway API stage name (e.g., `/v1`)
483
-
484
- - **Feature Configuration**: Control which features are enabled:
485
- - `ENABLE_COLLECTIONS_SEARCH`: Set to `true` (default) to enable collection search extensions (sort, fields). Set to `false` to disable.
486
- - `ENABLE_TRANSACTIONS_EXTENSIONS`: Set to `true` (default) to enable transaction extensions. Set to `false` to disable.
487
-
488
- ## Collection Pagination
489
-
490
- - **Overview**: The collections route supports pagination through optional query parameters.
491
- - **Parameters**:
492
- - `limit`: Controls the number of collections returned per page
493
- - `token`: Used to retrieve subsequent pages of results
494
- - **Response Structure**: The `links` field in the response contains a `next` link with the token for the next page of results.
495
- - **Example Usage**:
496
- ```shell
497
- curl -X "GET" "http://localhost:8080/collections?limit=1&token=example_token"
498
- ```
499
-
500
- ## Ingesting Sample Data CLI Tool
501
-
502
- - **Overview**: The `data_loader.py` script provides a convenient way to load STAC items into the database.
503
-
504
- - **Usage**:
505
- ```shell
506
- python3 data_loader.py --base-url http://localhost:8080
507
- ```
508
-
509
- - **Options**:
510
- ```
511
- --base-url TEXT Base URL of the STAC API [required]
512
- --collection-id TEXT ID of the collection to which items are added
513
- --use-bulk Use bulk insert method for items
514
- --data-dir PATH Directory containing collection.json and feature
515
- collection file
516
- --help Show this message and exit.
517
- ```
518
-
519
- - **Example Workflows**:
520
- - **Loading Sample Data**:
521
- ```shell
522
- python3 data_loader.py --base-url http://localhost:8080
523
- ```
524
- - **Loading Data to a Specific Collection**:
525
- ```shell
526
- python3 data_loader.py --base-url http://localhost:8080 --collection-id my-collection
527
- ```
528
- - **Using Bulk Insert for Performance**:
529
- ```shell
530
- python3 data_loader.py --base-url http://localhost:8080 --use-bulk
531
- ```
532
-
533
- ## Elasticsearch Mappings
534
-
535
- - **Overview**: Mappings apply to search index, not source data. They define how documents and their fields are stored and indexed.
536
- - **Implementation**:
537
- - Mappings are stored in index templates that are created on application startup
538
- - These templates are automatically applied when creating new Collection and Item indices
539
- - The `sfeos_helpers` package contains shared mapping definitions used by both Elasticsearch and OpenSearch backends
540
- - **Customization**: Custom mappings can be defined by extending the base mapping templates.
541
-
542
- ## Managing Elasticsearch Indices
543
-
544
- ### Snapshots
545
-
546
- - **Overview**: Snapshots provide a way to backup and restore your indices.
547
-
548
- - **Creating a Snapshot Repository**:
549
- ```shell
550
- curl -X "PUT" "http://localhost:9200/_snapshot/my_fs_backup" \
551
- -H 'Content-Type: application/json; charset=utf-8' \
552
- -d $'{
553
- "type": "fs",
554
- "settings": {
555
- "location": "/usr/share/elasticsearch/snapshots/my_fs_backup"
556
- }
557
- }'
558
- ```
559
- - This creates a snapshot repository that stores files in the elasticsearch/snapshots directory in this git repo clone
560
- - The elasticsearch.yml and compose files create a mapping from that directory to /usr/share/elasticsearch/snapshots within the Elasticsearch container and grant permissions for using it
561
-
562
- - **Creating a Snapshot**:
563
- ```shell
564
- curl -X "PUT" "http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2?wait_for_completion=true" \
565
- -H 'Content-Type: application/json; charset=utf-8' \
566
- -d $'{
567
- "metadata": {
568
- "taken_because": "dump of all items",
569
- "taken_by": "pvarner"
570
- },
571
- "include_global_state": false,
572
- "ignore_unavailable": false,
573
- "indices": "items_my-collection"
574
- }'
575
- ```
576
- - This creates a snapshot named my_snapshot_2 and waits for the action to be completed before returning
577
- - This can also be done asynchronously by omitting the wait_for_completion parameter, and queried for status later
578
- - The indices parameter determines which indices are snapshotted, and can include wildcards
579
-
580
- - **Viewing Snapshots**:
581
- ```shell
582
- # View a specific snapshot
583
- curl http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2
584
-
585
- # View all snapshots
586
- curl http://localhost:9200/_snapshot/my_fs_backup/_all
587
- ```
588
- - These commands allow you to check the status and details of your snapshots
589
-
590
- - **Restoring a Snapshot**:
591
- ```shell
592
- curl -X "POST" "http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2/_restore?wait_for_completion=true" \
593
- -H 'Content-Type: application/json; charset=utf-8' \
594
- -d $'{
595
- "include_aliases": false,
596
- "include_global_state": false,
597
- "ignore_unavailable": true,
598
- "rename_replacement": "items_$1-copy",
599
- "indices": "items_*",
600
- "rename_pattern": "items_(.+)"
601
- }'
602
- ```
603
- - This specific command will restore any indices that match items_* and rename them so that the new index name will be suffixed with -copy
604
- - The rename_pattern and rename_replacement parameters allow you to restore indices under new names
605
-
606
- - **Updating Collection References**:
607
- ```shell
608
- curl -X "POST" "http://localhost:9200/items_my-collection-copy/_update_by_query" \
609
- -H 'Content-Type: application/json; charset=utf-8' \
610
- -d $'{
611
- "query": {
612
- "match_all": {}
613
- },
614
- "script": {
615
- "lang": "painless",
616
- "params": {
617
- "collection": "my-collection-copy"
618
- },
619
- "source": "ctx._source.collection = params.collection"
620
- }
621
- }'
622
- ```
623
- - After restoring, the item documents have been restored in the new index (e.g., my-collection-copy), but the value of the collection field in those documents is still the original value of my-collection
624
- - This command updates these values to match the new collection name using Elasticsearch's Update By Query feature
625
-
626
- - **Creating a New Collection**:
627
- ```shell
628
- curl -X "POST" "http://localhost:8080/collections" \
629
- -H 'Content-Type: application/json' \
630
- -d $'{
631
- "id": "my-collection-copy"
632
- }'
633
- ```
634
- - The final step is to create a new collection through the API with the new name for each of the restored indices
635
- - This gives you a copy of the collection that has a resource URI (/collections/my-collection-copy) and can be correctly queried by collection name
636
-
637
- ### Reindexing
638
-
639
- - **Overview**: Reindexing allows you to copy documents from one index to another, optionally transforming them in the process.
640
-
641
- - **Use Cases**:
642
- - Apply changes to documents
643
- - Correct dynamically generated mappings
644
- - Transform data (e.g., lowercase identifiers)
645
- - The index templates will make sure that manually created indices will also have the correct mappings and settings
646
-
647
- - **Example: Reindexing with Transformation**:
648
- ```shell
649
- curl -X "POST" "http://localhost:9200/_reindex" \
650
- -H 'Content-Type: application/json' \
651
- -d $'{
652
- "source": {
653
- "index": "items_my-collection-lower_my-collection-hex-000001"
654
- },
655
- "dest": {
656
- "index": "items_my-collection-lower_my-collection-hex-000002"
657
- },
658
- "script": {
659
- "source": "ctx._source.id = ctx._source.id.toLowerCase()",
660
- "lang": "painless"
661
- }
662
- }'
663
- ```
664
- - In this example, we make a copy of an existing Item index but change the Item identifier to be lowercase
665
- - The script parameter allows you to transform documents during the reindexing process
666
-
667
- - **Updating Aliases**:
668
- ```shell
669
- curl -X "POST" "http://localhost:9200/_aliases" \
670
- -H 'Content-Type: application/json' \
671
- -d $'{
672
- "actions": [
673
- {
674
- "remove": {
675
- "index": "*",
676
- "alias": "items_my-collection"
677
- }
678
- },
679
- {
680
- "add": {
681
- "index": "items_my-collection-lower_my-collection-hex-000002",
682
- "alias": "items_my-collection"
683
- }
684
- }
685
- ]
686
- }'
687
- ```
688
- - If you are happy with the data in the newly created index, you can move the alias items_my-collection to the new index
689
- - This makes the modified Items with lowercase identifiers visible to users accessing my-collection in the STAC API
690
- - Using aliases allows you to switch between different index versions without changing the API endpoint
691
-
692
- ## Auth
693
-
694
- - **Overview**: Authentication is an optional feature that can be enabled through Route Dependencies.
695
- - **Implementation Options**:
696
- - Basic authentication
697
- - OAuth2 with Keycloak
698
- - Custom route dependencies
699
- - **Configuration**: Authentication can be configured using the `STAC_FASTAPI_ROUTE_DEPENDENCIES` environment variable.
700
- - **Examples and Documentation**: Detailed examples and implementation guides can be found in the [examples/auth](examples/auth) directory.
701
-
702
- ## Aggregation
703
-
704
- - **Supported Aggregations**:
705
- - Spatial aggregations of points and geometries
706
- - Frequency distribution aggregation of any property including dates
707
- - Temporal distribution of datetime values
708
-
709
- - **Endpoint Locations**:
710
- - Root Catalog level: `/aggregations`
711
- - Collection level: `/<collection_id>/aggregations`
712
-
713
- - **Implementation Details**: The `sfeos_helpers.aggregation` package provides specialized functionality for both Elasticsearch and OpenSearch backends.
714
-
715
- - **Documentation**: Detailed information about supported aggregations can be found in [the aggregation docs](./docs/src/aggregation.md).
716
-
717
-
718
- ## Rate Limiting
719
-
720
- - **Overview**: Rate limiting is an optional security feature that controls API request frequency on a remote address basis.
721
-
722
- - **Configuration**: Enabled by setting the `STAC_FASTAPI_RATE_LIMIT` environment variable:
723
- ```
724
- STAC_FASTAPI_RATE_LIMIT=500/minute
725
- ```
726
-
727
- - **Functionality**:
728
- - Limits each client to a specified number of requests per time period (e.g., 500 requests per minute)
729
- - Helps prevent API abuse and maintains system stability
730
- - Ensures fair resource allocation among all clients
731
-
732
- - **Examples**: Implementation examples are available in the [examples/rate_limit](examples/rate_limit) directory.
@@ -1,10 +0,0 @@
1
- stac_fastapi/opensearch/__init__.py,sha256=iJWMUgn7mUvmuPQSO_FlyhJ5eDdbbfmGv1qnFOX5-qk,28
2
- stac_fastapi/opensearch/app.py,sha256=paRSzdkT3yxkegC3KEg98CA7PpNQ0C2LW0Mozb_LcP0,10025
3
- stac_fastapi/opensearch/config.py,sha256=zGx4-4c5zEnu_Bh8Ra3SkIC83tluDiz-wKYQclRRDJA,5179
4
- stac_fastapi/opensearch/database_logic.py,sha256=WzVor77OGJrMhBM-LSwUc5cKjKtlTEuxsuzS_OzfYv4,67817
5
- stac_fastapi/opensearch/version.py,sha256=FuGC3fKnAmD4Wk95swJ6qCVBs5mZiShrlRKuSH-voyE,45
6
- stac_fastapi_opensearch-6.5.1.dist-info/METADATA,sha256=i4JZbltYaOznnduQjNKH_PNqKcnzE7d_DITxqNHOuMQ,42048
7
- stac_fastapi_opensearch-6.5.1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
8
- stac_fastapi_opensearch-6.5.1.dist-info/entry_points.txt,sha256=zjZ0Xsr9BUNJqMkdPpl6zEIUykv1uFdJtNELFRChp0w,76
9
- stac_fastapi_opensearch-6.5.1.dist-info/top_level.txt,sha256=vqn-D9-HsRPTTxy0Vk_KkDmTiMES4owwBQ3ydSZYb2s,13
10
- stac_fastapi_opensearch-6.5.1.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- stac_fastapi