stac-fastapi-opensearch 4.2.0__tar.gz → 5.0.0a0__tar.gz

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.
Files changed (20) hide show
  1. stac_fastapi_opensearch-5.0.0a0/PKG-INFO +560 -0
  2. stac_fastapi_opensearch-5.0.0a0/README.md +539 -0
  3. {stac_fastapi_opensearch-4.2.0 → stac_fastapi_opensearch-5.0.0a0}/setup.py +2 -1
  4. {stac_fastapi_opensearch-4.2.0 → stac_fastapi_opensearch-5.0.0a0}/stac_fastapi/opensearch/app.py +4 -4
  5. {stac_fastapi_opensearch-4.2.0 → stac_fastapi_opensearch-5.0.0a0}/stac_fastapi/opensearch/config.py +2 -1
  6. {stac_fastapi_opensearch-4.2.0 → stac_fastapi_opensearch-5.0.0a0}/stac_fastapi/opensearch/database_logic.py +70 -155
  7. stac_fastapi_opensearch-5.0.0a0/stac_fastapi/opensearch/version.py +2 -0
  8. stac_fastapi_opensearch-5.0.0a0/stac_fastapi_opensearch.egg-info/PKG-INFO +560 -0
  9. {stac_fastapi_opensearch-4.2.0 → stac_fastapi_opensearch-5.0.0a0}/stac_fastapi_opensearch.egg-info/requires.txt +2 -1
  10. stac_fastapi_opensearch-4.2.0/PKG-INFO +0 -367
  11. stac_fastapi_opensearch-4.2.0/README.md +0 -346
  12. stac_fastapi_opensearch-4.2.0/stac_fastapi/opensearch/version.py +0 -2
  13. stac_fastapi_opensearch-4.2.0/stac_fastapi_opensearch.egg-info/PKG-INFO +0 -367
  14. {stac_fastapi_opensearch-4.2.0 → stac_fastapi_opensearch-5.0.0a0}/setup.cfg +0 -0
  15. {stac_fastapi_opensearch-4.2.0 → stac_fastapi_opensearch-5.0.0a0}/stac_fastapi/opensearch/__init__.py +0 -0
  16. {stac_fastapi_opensearch-4.2.0 → stac_fastapi_opensearch-5.0.0a0}/stac_fastapi_opensearch.egg-info/SOURCES.txt +0 -0
  17. {stac_fastapi_opensearch-4.2.0 → stac_fastapi_opensearch-5.0.0a0}/stac_fastapi_opensearch.egg-info/dependency_links.txt +0 -0
  18. {stac_fastapi_opensearch-4.2.0 → stac_fastapi_opensearch-5.0.0a0}/stac_fastapi_opensearch.egg-info/entry_points.txt +0 -0
  19. {stac_fastapi_opensearch-4.2.0 → stac_fastapi_opensearch-5.0.0a0}/stac_fastapi_opensearch.egg-info/not-zip-safe +0 -0
  20. {stac_fastapi_opensearch-4.2.0 → stac_fastapi_opensearch-5.0.0a0}/stac_fastapi_opensearch.egg-info/top_level.txt +0 -0
@@ -0,0 +1,560 @@
1
+ Metadata-Version: 2.1
2
+ Name: stac_fastapi_opensearch
3
+ Version: 5.0.0a0
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
+ Provides-Extra: dev
19
+ Provides-Extra: docs
20
+ Provides-Extra: server
21
+
22
+ # stac-fastapi-elasticsearch-opensearch
23
+
24
+ <!-- markdownlint-disable MD033 MD041 -->
25
+
26
+
27
+ <p align="left">
28
+ <img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/sfeos.png" width=1000>
29
+ </p>
30
+
31
+ **Jump to:** [Project Introduction](#project-introduction---what-is-sfeos) | [Quick Start](#quick-start) | [Table of Contents](#table-of-contents)
32
+
33
+ [![Downloads](https://static.pepy.tech/badge/stac-fastapi-core?color=blue)](https://pepy.tech/project/stac-fastapi-core)
34
+ [![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)
35
+ [![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)
36
+ [![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)
37
+ [![PyPI version](https://img.shields.io/pypi/v/stac-fastapi-elasticsearch.svg?color=blue)](https://pypi.org/project/stac-fastapi-elasticsearch/)
38
+ [![STAC](https://img.shields.io/badge/STAC-1.1.0-blue.svg)](https://github.com/radiantearth/stac-spec/tree/v1.1.0)
39
+ [![stac-fastapi](https://img.shields.io/badge/stac--fastapi-5.2.0-blue.svg)](https://github.com/stac-utils/stac-fastapi)
40
+
41
+ ## Sponsors & Supporters
42
+
43
+ The following organizations have contributed time and/or funding to support the development of this project:
44
+
45
+ <p align="left">
46
+ <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>
47
+ <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>
48
+ <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>
49
+ </p>
50
+
51
+ ## Project Introduction - What is SFEOS?
52
+
53
+ 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:
54
+
55
+ - **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
56
+ - **Implement standardized STAC APIs** that support complex spatial, temporal, and property-based queries across large collections of geospatial data
57
+ - **Scale to millions of geospatial assets** with fast search performance through optimized spatial indexing and query capabilities
58
+ - **Support OGC-compliant filtering** including spatial operations (intersects, contains, etc.) and temporal queries
59
+ - **Perform geospatial aggregations** to analyze data distribution across space and time
60
+
61
+ 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.
62
+
63
+
64
+
65
+ ## Common Deployment Patterns
66
+
67
+ stac-fastapi-elasticsearch-opensearch can be deployed in several ways depending on your needs:
68
+
69
+ - **Containerized Application**: Run as a Docker container with connections to Elasticsearch/OpenSearch databases
70
+ - **Serverless Function**: Deploy as AWS Lambda or similar serverless function with API Gateway
71
+ - **Traditional Server**: Run on virtual machines or bare metal servers in your infrastructure
72
+ - **Kubernetes**: Deploy as part of a larger microservices architecture with container orchestration
73
+
74
+ The implementation is flexible and can scale from small local deployments to large production environments serving millions of geospatial assets.
75
+
76
+ ## Technologies
77
+
78
+ This project is built on the following technologies: STAC, stac-fastapi, FastAPI, Elasticsearch, Python, OpenSearch
79
+
80
+ <p align="left">
81
+ <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>
82
+ <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>
83
+ <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>
84
+ <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>
85
+ <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>
86
+ </p>
87
+
88
+ ## Table of Contents
89
+
90
+ - [Documentation & Resources](#documentation--resources)
91
+ - [Package Structure](#package-structure)
92
+ - [Examples](#examples)
93
+ - [Performance](#performance)
94
+ - [Quick Start](#quick-start)
95
+ - [Installation](#installation)
96
+ - [Running Locally](#running-locally)
97
+ - [Configuration reference](#configuration-reference)
98
+ - [Interacting with the API](#interacting-with-the-api)
99
+ - [Configure the API](#configure-the-api)
100
+ - [Collection pagination](#collection-pagination)
101
+ - [Ingesting Sample Data CLI Tool](#ingesting-sample-data-cli-tool)
102
+ - [Elasticsearch Mappings](#elasticsearch-mappings)
103
+ - [Managing Elasticsearch Indices](#managing-elasticsearch-indices)
104
+ - [Snapshots](#snapshots)
105
+ - [Reindexing](#reindexing)
106
+ - [Auth](#auth)
107
+ - [Aggregation](#aggregation)
108
+ - [Rate Limiting](#rate-limiting)
109
+
110
+ ## Documentation & Resources
111
+
112
+ - **Online Documentation**: [https://stac-utils.github.io/stac-fastapi-elasticsearch-opensearch](https://stac-utils.github.io/stac-fastapi-elasticsearch-opensearch/)
113
+ - **Source Code**: [https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch)
114
+ - **API Examples**: [Postman Documentation](https://documenter.getpostman.com/view/12888943/2s8ZDSdRHA) - Examples of how to use the API endpoints
115
+ - **Community**:
116
+ - [Gitter Chat](https://app.gitter.im/#/room/#stac-fastapi-elasticsearch_community:gitter.im) - For real-time discussions
117
+ - [GitHub Discussions](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/discussions) - For longer-form questions and answers
118
+
119
+ ## Package Structure
120
+
121
+ This project is organized into several packages, each with a specific purpose:
122
+
123
+ - **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.
124
+
125
+ - **sfeos_helpers**: Shared helper functions and utilities used by both the Elasticsearch and OpenSearch backends. This package includes:
126
+ - `database`: Specialized modules for index, document, and database utility operations
127
+ - `aggregation`: Elasticsearch/OpenSearch-specific aggregation functionality
128
+ - Shared logic and utilities that improve code reuse between backends
129
+
130
+ - **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`.
131
+ -
132
+ - **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`.
133
+
134
+ ## Examples
135
+
136
+ The `/examples` directory contains several useful examples and reference implementations:
137
+
138
+ - **pip_docker**: Examples of running stac-fastapi-elasticsearch from PyPI in Docker without needing any code from the repository
139
+ - **auth**: Authentication examples including:
140
+ - Basic authentication
141
+ - OAuth2 with Keycloak
142
+ - Route dependencies configuration
143
+ - **rate_limit**: Example of implementing rate limiting for API requests
144
+ - **postman_collections**: Postman collection files you can import for testing API endpoints
145
+
146
+ These examples provide practical reference implementations for various deployment scenarios and features.
147
+
148
+ ## Performance
149
+
150
+ ### Direct Response Mode
151
+
152
+ - 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.
153
+ - **Control via environment variable**: Set `ENABLE_DIRECT_RESPONSE=true` to enable this feature.
154
+ - **How it works**: When enabled, endpoints return Starlette Response objects directly, bypassing FastAPI's default serialization for improved performance.
155
+ - **Important limitation**: All FastAPI dependencies (including authentication, custom status codes, and validation) are disabled for all routes when this mode is enabled.
156
+ - **Best use case**: This mode is best suited for public or read-only APIs where authentication and custom logic are not required.
157
+ - **Default setting**: `false` for safety.
158
+ - **More information**: See [issue #347](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/issues/347) for background and implementation details.
159
+
160
+ ## Quick Start
161
+
162
+ This section helps you get up and running with stac-fastapi-elasticsearch-opensearch quickly.
163
+
164
+ ### Installation
165
+
166
+ - **For versions 4.0.0a1 and newer** (PEP 625 compliant naming):
167
+ ```bash
168
+ pip install stac-fastapi-elasticsearch # Elasticsearch backend
169
+ pip install stac-fastapi-opensearch # Opensearch backend
170
+ pip install stac-fastapi-core # Core library
171
+ ```
172
+
173
+ - **For versions 4.0.0a0 and older**:
174
+ ```bash
175
+ pip install stac-fastapi.elasticsearch # Elasticsearch backend
176
+ pip install stac-fastapi.opensearch # Opensearch backend
177
+ pip install stac-fastapi.core # Core library
178
+ ```
179
+
180
+ > **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.
181
+
182
+ ### Running Locally
183
+
184
+ There are two main ways to run the API locally:
185
+
186
+ #### Using Pre-built Docker Images
187
+
188
+ - We provide ready-to-use Docker images through GitHub Container Registry:
189
+ - [ElasticSearch backend](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pkgs/container/stac-fastapi-es)
190
+ - [OpenSearch backend](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pkgs/container/stac-fastapi-os)
191
+
192
+ - **Pull and run the images**:
193
+ ```shell
194
+ # For Elasticsearch backend
195
+ docker pull ghcr.io/stac-utils/stac-fastapi-es:latest
196
+
197
+ # For OpenSearch backend
198
+ docker pull ghcr.io/stac-utils/stac-fastapi-os:latest
199
+ ```
200
+
201
+ #### Using Docker Compose
202
+
203
+ - **Prerequisites**: Ensure [Docker Compose](https://docs.docker.com/compose/install/) or [Podman Compose](https://podman-desktop.io/docs/compose) is installed on your machine.
204
+
205
+ - **Start the API**:
206
+ ```shell
207
+ docker compose up elasticsearch app-elasticsearch
208
+ ```
209
+
210
+ - **Configuration**: By default, Docker Compose uses Elasticsearch 8.x and OpenSearch 2.11.1. To use different versions, create a `.env` file:
211
+ ```shell
212
+ ELASTICSEARCH_VERSION=8.11.0
213
+ OPENSEARCH_VERSION=2.11.1
214
+ ENABLE_DIRECT_RESPONSE=false
215
+ ```
216
+
217
+ - **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.
218
+
219
+
220
+
221
+ ## Configuration Reference
222
+
223
+ You can customize additional settings in your `.env` file:
224
+
225
+ | Variable | Description | Default | Required |
226
+ |------------------------------|--------------------------------------------------------------------------------------|--------------------------|---------------------------------------------------------------------------------------------|
227
+ | `ES_HOST` | Hostname for external Elasticsearch/OpenSearch. | `localhost` | Optional |
228
+ | `ES_PORT` | Port for Elasticsearch/OpenSearch. | `9200` (ES) / `9202` (OS)| Optional |
229
+ | `ES_USE_SSL` | Use SSL for connecting to Elasticsearch/OpenSearch. | `false` | Optional |
230
+ | `ES_VERIFY_CERTS` | Verify SSL certificates when connecting. | `false` | Optional |
231
+ | `STAC_FASTAPI_TITLE` | Title of the API in the documentation. | `stac-fastapi-<backend>` | Optional |
232
+ | `STAC_FASTAPI_DESCRIPTION` | Description of the API in the documentation. | N/A | Optional |
233
+ | `STAC_FASTAPI_VERSION` | API version. | `2.1` | Optional |
234
+ | `STAC_FASTAPI_LANDING_PAGE_ID` | Landing page ID | `stac-fastapi` | Optional |
235
+ | `APP_HOST` | Server bind address. | `0.0.0.0` | Optional |
236
+ | `APP_PORT` | Server port. | `8080` | Optional |
237
+ | `ENVIRONMENT` | Runtime environment. | `local` | Optional |
238
+ | `WEB_CONCURRENCY` | Number of worker processes. | `10` | Optional |
239
+ | `RELOAD` | Enable auto-reload for development. | `true` | Optional |
240
+ | `STAC_FASTAPI_RATE_LIMIT` | API rate limit per client. | `200/minute` | Optional |
241
+ | `BACKEND` | Tests-related variable | `elasticsearch` or `opensearch` based on the backend | Optional |
242
+ | `ELASTICSEARCH_VERSION` | Version of Elasticsearch to use. | `8.11.0` | Optional | |
243
+ | `OPENSEARCH_VERSION` | OpenSearch version | `2.11.1` | Optional
244
+ | `ENABLE_DIRECT_RESPONSE` | Enable direct response for maximum performance (disables all FastAPI dependencies, including authentication, custom status codes, and validation) | `false` | Optional
245
+ | `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 |
246
+ | `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 |
247
+ | `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 |
248
+
249
+ > [!NOTE]
250
+ > The variables `ES_HOST`, `ES_PORT`, `ES_USE_SSL`, and `ES_VERIFY_CERTS` 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.
251
+
252
+ ## Interacting with the API
253
+
254
+ - **Creating a Collection**:
255
+ ```shell
256
+ curl -X "POST" "http://localhost:8080/collections" \
257
+ -H 'Content-Type: application/json; charset=utf-8' \
258
+ -d $'{
259
+ "id": "my_collection"
260
+ }'
261
+ ```
262
+
263
+ - **Adding an Item to a Collection**:
264
+ ```shell
265
+ curl -X "POST" "http://localhost:8080/collections/my_collection/items" \
266
+ -H 'Content-Type: application/json; charset=utf-8' \
267
+ -d @item.json
268
+ ```
269
+
270
+ - **Searching for Items**:
271
+ ```shell
272
+ curl -X "GET" "http://localhost:8080/search" \
273
+ -H 'Content-Type: application/json; charset=utf-8' \
274
+ -d $'{
275
+ "collections": ["my_collection"],
276
+ "limit": 10
277
+ }'
278
+ ```
279
+
280
+ - **Filtering by Bbox**:
281
+ ```shell
282
+ curl -X "GET" "http://localhost:8080/search" \
283
+ -H 'Content-Type: application/json; charset=utf-8' \
284
+ -d $'{
285
+ "collections": ["my_collection"],
286
+ "bbox": [-180, -90, 180, 90]
287
+ }'
288
+ ```
289
+
290
+ - **Filtering by Datetime**:
291
+ ```shell
292
+ curl -X "GET" "http://localhost:8080/search" \
293
+ -H 'Content-Type: application/json; charset=utf-8' \
294
+ -d $'{
295
+ "collections": ["my_collection"],
296
+ "datetime": "2020-01-01T00:00:00Z/2020-12-31T23:59:59Z"
297
+ }'
298
+ ```
299
+
300
+ ## Configure the API
301
+
302
+ - **API Title and Description**: By default set to `stac-fastapi-<backend>`. Customize these by setting:
303
+ - `STAC_FASTAPI_TITLE`: Changes the API title in the documentation
304
+ - `STAC_FASTAPI_DESCRIPTION`: Changes the API description in the documentation
305
+
306
+ - **Database Indices**: By default, the API reads from and writes to:
307
+ - `collections` index for collections
308
+ - `items_<collection name>` indices for items
309
+ - Customize with `STAC_COLLECTIONS_INDEX` and `STAC_ITEMS_INDEX_PREFIX` environment variables
310
+
311
+ - **Root Path Configuration**: The application root path is the base URL by default.
312
+ - For AWS Lambda with Gateway API: Set `STAC_FASTAPI_ROOT_PATH` to match the Gateway API stage name (e.g., `/v1`)
313
+
314
+
315
+ ## Collection Pagination
316
+
317
+ - **Overview**: The collections route supports pagination through optional query parameters.
318
+ - **Parameters**:
319
+ - `limit`: Controls the number of collections returned per page
320
+ - `token`: Used to retrieve subsequent pages of results
321
+ - **Response Structure**: The `links` field in the response contains a `next` link with the token for the next page of results.
322
+ - **Example Usage**:
323
+ ```shell
324
+ curl -X "GET" "http://localhost:8080/collections?limit=1&token=example_token"
325
+ ```
326
+
327
+ ## Ingesting Sample Data CLI Tool
328
+
329
+ - **Overview**: The `data_loader.py` script provides a convenient way to load STAC items into the database.
330
+
331
+ - **Usage**:
332
+ ```shell
333
+ python3 data_loader.py --base-url http://localhost:8080
334
+ ```
335
+
336
+ - **Options**:
337
+ ```
338
+ --base-url TEXT Base URL of the STAC API [required]
339
+ --collection-id TEXT ID of the collection to which items are added
340
+ --use-bulk Use bulk insert method for items
341
+ --data-dir PATH Directory containing collection.json and feature
342
+ collection file
343
+ --help Show this message and exit.
344
+ ```
345
+
346
+ - **Example Workflows**:
347
+ - **Loading Sample Data**:
348
+ ```shell
349
+ python3 data_loader.py --base-url http://localhost:8080
350
+ ```
351
+ - **Loading Data to a Specific Collection**:
352
+ ```shell
353
+ python3 data_loader.py --base-url http://localhost:8080 --collection-id my-collection
354
+ ```
355
+ - **Using Bulk Insert for Performance**:
356
+ ```shell
357
+ python3 data_loader.py --base-url http://localhost:8080 --use-bulk
358
+ ```
359
+
360
+ ## Elasticsearch Mappings
361
+
362
+ - **Overview**: Mappings apply to search index, not source data. They define how documents and their fields are stored and indexed.
363
+ - **Implementation**:
364
+ - Mappings are stored in index templates that are created on application startup
365
+ - These templates are automatically applied when creating new Collection and Item indices
366
+ - The `sfeos_helpers` package contains shared mapping definitions used by both Elasticsearch and OpenSearch backends
367
+ - **Customization**: Custom mappings can be defined by extending the base mapping templates.
368
+
369
+ ## Managing Elasticsearch Indices
370
+
371
+ ### Snapshots
372
+
373
+ - **Overview**: Snapshots provide a way to backup and restore your indices.
374
+
375
+ - **Creating a Snapshot Repository**:
376
+ ```shell
377
+ curl -X "PUT" "http://localhost:9200/_snapshot/my_fs_backup" \
378
+ -H 'Content-Type: application/json; charset=utf-8' \
379
+ -d $'{
380
+ "type": "fs",
381
+ "settings": {
382
+ "location": "/usr/share/elasticsearch/snapshots/my_fs_backup"
383
+ }
384
+ }'
385
+ ```
386
+ - This creates a snapshot repository that stores files in the elasticsearch/snapshots directory in this git repo clone
387
+ - 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
388
+
389
+ - **Creating a Snapshot**:
390
+ ```shell
391
+ curl -X "PUT" "http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2?wait_for_completion=true" \
392
+ -H 'Content-Type: application/json; charset=utf-8' \
393
+ -d $'{
394
+ "metadata": {
395
+ "taken_because": "dump of all items",
396
+ "taken_by": "pvarner"
397
+ },
398
+ "include_global_state": false,
399
+ "ignore_unavailable": false,
400
+ "indices": "items_my-collection"
401
+ }'
402
+ ```
403
+ - This creates a snapshot named my_snapshot_2 and waits for the action to be completed before returning
404
+ - This can also be done asynchronously by omitting the wait_for_completion parameter, and queried for status later
405
+ - The indices parameter determines which indices are snapshotted, and can include wildcards
406
+
407
+ - **Viewing Snapshots**:
408
+ ```shell
409
+ # View a specific snapshot
410
+ curl http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2
411
+
412
+ # View all snapshots
413
+ curl http://localhost:9200/_snapshot/my_fs_backup/_all
414
+ ```
415
+ - These commands allow you to check the status and details of your snapshots
416
+
417
+ - **Restoring a Snapshot**:
418
+ ```shell
419
+ curl -X "POST" "http://localhost:9200/_snapshot/my_fs_backup/my_snapshot_2/_restore?wait_for_completion=true" \
420
+ -H 'Content-Type: application/json; charset=utf-8' \
421
+ -d $'{
422
+ "include_aliases": false,
423
+ "include_global_state": false,
424
+ "ignore_unavailable": true,
425
+ "rename_replacement": "items_$1-copy",
426
+ "indices": "items_*",
427
+ "rename_pattern": "items_(.+)"
428
+ }'
429
+ ```
430
+ - This specific command will restore any indices that match items_* and rename them so that the new index name will be suffixed with -copy
431
+ - The rename_pattern and rename_replacement parameters allow you to restore indices under new names
432
+
433
+ - **Updating Collection References**:
434
+ ```shell
435
+ curl -X "POST" "http://localhost:9200/items_my-collection-copy/_update_by_query" \
436
+ -H 'Content-Type: application/json; charset=utf-8' \
437
+ -d $'{
438
+ "query": {
439
+ "match_all": {}
440
+ },
441
+ "script": {
442
+ "lang": "painless",
443
+ "params": {
444
+ "collection": "my-collection-copy"
445
+ },
446
+ "source": "ctx._source.collection = params.collection"
447
+ }
448
+ }'
449
+ ```
450
+ - 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
451
+ - This command updates these values to match the new collection name using Elasticsearch's Update By Query feature
452
+
453
+ - **Creating a New Collection**:
454
+ ```shell
455
+ curl -X "POST" "http://localhost:8080/collections" \
456
+ -H 'Content-Type: application/json' \
457
+ -d $'{
458
+ "id": "my-collection-copy"
459
+ }'
460
+ ```
461
+ - The final step is to create a new collection through the API with the new name for each of the restored indices
462
+ - 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
463
+
464
+ ### Reindexing
465
+
466
+ - **Overview**: Reindexing allows you to copy documents from one index to another, optionally transforming them in the process.
467
+
468
+ - **Use Cases**:
469
+ - Apply changes to documents
470
+ - Correct dynamically generated mappings
471
+ - Transform data (e.g., lowercase identifiers)
472
+ - The index templates will make sure that manually created indices will also have the correct mappings and settings
473
+
474
+ - **Example: Reindexing with Transformation**:
475
+ ```shell
476
+ curl -X "POST" "http://localhost:9200/_reindex" \
477
+ -H 'Content-Type: application/json' \
478
+ -d $'{
479
+ "source": {
480
+ "index": "items_my-collection-lower_my-collection-hex-000001"
481
+ },
482
+ "dest": {
483
+ "index": "items_my-collection-lower_my-collection-hex-000002"
484
+ },
485
+ "script": {
486
+ "source": "ctx._source.id = ctx._source.id.toLowerCase()",
487
+ "lang": "painless"
488
+ }
489
+ }'
490
+ ```
491
+ - In this example, we make a copy of an existing Item index but change the Item identifier to be lowercase
492
+ - The script parameter allows you to transform documents during the reindexing process
493
+
494
+ - **Updating Aliases**:
495
+ ```shell
496
+ curl -X "POST" "http://localhost:9200/_aliases" \
497
+ -H 'Content-Type: application/json' \
498
+ -d $'{
499
+ "actions": [
500
+ {
501
+ "remove": {
502
+ "index": "*",
503
+ "alias": "items_my-collection"
504
+ }
505
+ },
506
+ {
507
+ "add": {
508
+ "index": "items_my-collection-lower_my-collection-hex-000002",
509
+ "alias": "items_my-collection"
510
+ }
511
+ }
512
+ ]
513
+ }'
514
+ ```
515
+ - If you are happy with the data in the newly created index, you can move the alias items_my-collection to the new index
516
+ - This makes the modified Items with lowercase identifiers visible to users accessing my-collection in the STAC API
517
+ - Using aliases allows you to switch between different index versions without changing the API endpoint
518
+
519
+ ## Auth
520
+
521
+ - **Overview**: Authentication is an optional feature that can be enabled through Route Dependencies.
522
+ - **Implementation Options**:
523
+ - Basic authentication
524
+ - OAuth2 with Keycloak
525
+ - Custom route dependencies
526
+ - **Configuration**: Authentication can be configured using the `STAC_FASTAPI_ROUTE_DEPENDENCIES` environment variable.
527
+ - **Examples and Documentation**: Detailed examples and implementation guides can be found in the [examples/auth](examples/auth) directory.
528
+
529
+ ## Aggregation
530
+
531
+ - **Supported Aggregations**:
532
+ - Spatial aggregations of points and geometries
533
+ - Frequency distribution aggregation of any property including dates
534
+ - Temporal distribution of datetime values
535
+
536
+ - **Endpoint Locations**:
537
+ - Root Catalog level: `/aggregations`
538
+ - Collection level: `/<collection_id>/aggregations`
539
+
540
+ - **Implementation Details**: The `sfeos_helpers.aggregation` package provides specialized functionality for both Elasticsearch and OpenSearch backends.
541
+
542
+ - **Documentation**: Detailed information about supported aggregations can be found in [the aggregation docs](./docs/src/aggregation.md).
543
+
544
+
545
+ ## Rate Limiting
546
+
547
+ - **Overview**: Rate limiting is an optional security feature that controls API request frequency on a remote address basis.
548
+
549
+ - **Configuration**: Enabled by setting the `STAC_FASTAPI_RATE_LIMIT` environment variable:
550
+ ```
551
+ STAC_FASTAPI_RATE_LIMIT=500/minute
552
+ ```
553
+
554
+ - **Functionality**:
555
+ - Limits each client to a specified number of requests per time period (e.g., 500 requests per minute)
556
+ - Helps prevent API abuse and maintains system stability
557
+ - Ensures fair resource allocation among all clients
558
+
559
+ - **Examples**: Implementation examples are available in the [examples/rate_limit](examples/rate_limit) directory.
560
+