Skip to content

Commit a0b77cb

Browse files
authored
Timeout setting for Opensearch and Elasticsearch (#408)
**Description:** Added timeout setting in Opensearch & Elasticsearch config which should only be relevant if user sets "ES_TIMEOUT" **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [x] Documentation has been updated to reflect changes, if applicable - [x] Changes are added to the changelog
1 parent b057c51 commit a0b77cb

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

CHANGELOG.md

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

99
## [Unreleased]
1010

11+
### Added
12+
13+
- Added the ability to set timeout for Opensearch and Elasticsearch clients by setting the environmental variable `ES_TIMEOUT` [#408](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/408)
14+
1115
## [v6.0.0] - 2025-06-22
1216

1317
### Added

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,26 +207,27 @@ You can customize additional settings in your `.env` file:
207207
| `ES_PORT` | Port for Elasticsearch/OpenSearch. | `9200` (ES) / `9202` (OS)| Optional |
208208
| `ES_USE_SSL` | Use SSL for connecting to Elasticsearch/OpenSearch. | `false` | Optional |
209209
| `ES_VERIFY_CERTS` | Verify SSL certificates when connecting. | `false` | Optional |
210+
| `ES_TIMEOUT` | Client timeout for Elasticsearch/OpenSearch. | DB client default | Optional |
210211
| `STAC_FASTAPI_TITLE` | Title of the API in the documentation. | `stac-fastapi-<backend>` | Optional |
211212
| `STAC_FASTAPI_DESCRIPTION` | Description of the API in the documentation. | N/A | Optional |
212213
| `STAC_FASTAPI_VERSION` | API version. | `2.1` | Optional |
213-
| `STAC_FASTAPI_LANDING_PAGE_ID` | Landing page ID | `stac-fastapi` | Optional |
214+
| `STAC_FASTAPI_LANDING_PAGE_ID` | Landing page ID | `stac-fastapi` | Optional |
214215
| `APP_HOST` | Server bind address. | `0.0.0.0` | Optional |
215216
| `APP_PORT` | Server port. | `8080` | Optional |
216217
| `ENVIRONMENT` | Runtime environment. | `local` | Optional |
217218
| `WEB_CONCURRENCY` | Number of worker processes. | `10` | Optional |
218219
| `RELOAD` | Enable auto-reload for development. | `true` | Optional |
219220
| `STAC_FASTAPI_RATE_LIMIT` | API rate limit per client. | `200/minute` | Optional |
220-
| `BACKEND` | Tests-related variable | `elasticsearch` or `opensearch` based on the backend | Optional |
221-
| `ELASTICSEARCH_VERSION` | Version of Elasticsearch to use. | `8.11.0` | Optional | |
222-
| `OPENSEARCH_VERSION` | OpenSearch version | `2.11.1` | Optional
223-
| `ENABLE_DIRECT_RESPONSE` | Enable direct response for maximum performance (disables all FastAPI dependencies, including authentication, custom status codes, and validation) | `false` | Optional
224-
| `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 |
225-
| `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 |
221+
| `BACKEND` | Tests-related variable | `elasticsearch` or `opensearch` based on the backend | Optional |
222+
| `ELASTICSEARCH_VERSION` | Version of Elasticsearch to use. | `8.11.0` | Optional |
223+
| `OPENSEARCH_VERSION` | OpenSearch version | `2.11.1` | Optional |
224+
| `ENABLE_DIRECT_RESPONSE` | Enable direct response for maximum performance (disables all FastAPI dependencies, including authentication, custom status codes, and validation) | `false` | Optional |
225+
| `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 |
226+
| `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 |
226227
| `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 |
227228

228229
> [!NOTE]
229-
> 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.
230+
> The variables `ES_HOST`, `ES_PORT`, `ES_USE_SSL`, `ES_VERIFY_CERTS` and `ES_TIMEOUT` apply to both Elasticsearch and OpenSearch backends, so there is no need to rename the key names to `OS_` even if you're using OpenSearch.
230231
231232
## Interacting with the API
232233

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ def _es_config() -> Dict[str, Any]:
5656
if (u := os.getenv("ES_USER")) and (p := os.getenv("ES_PASS")):
5757
config["http_auth"] = (u, p)
5858

59+
# Include timeout setting if set
60+
if request_timeout := os.getenv("ES_TIMEOUT"):
61+
config["request_timeout"] = request_timeout
62+
5963
# Explicitly exclude SSL settings when not using SSL
6064
if not use_ssl:
6165
return config

stac_fastapi/opensearch/stac_fastapi/opensearch/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ def _es_config() -> Dict[str, Any]:
5353

5454
config["headers"] = headers
5555

56+
# Include timeout setting if set
57+
if timeout := os.getenv("ES_TIMEOUT"):
58+
config["timeout"] = timeout
59+
5660
# Explicitly exclude SSL settings when not using SSL
5761
if not use_ssl:
5862
return config

0 commit comments

Comments
 (0)