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