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