Skip to content

Commit dffba5d

Browse files
authored
feat: more configuration options for Elasticsearch/OpenSearch (#349)
**Related Issue(s):** - #348 **Description:** Allow to configure multiple Elasticsearch/OpenSearch hosts (comma-separated) and enable `http_compress` by default. **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [ ] Documentation has been updated to reflect changes, if applicable - [x] Changes are added to the changelog
1 parent b016945 commit dffba5d

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Added
11+
- Option to configure multiple Elasticsearch/OpenSearch hosts and enable `http_compress`. [#349](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/349)
12+
1013
### Changed
1114

1215
## [v3.2.4] - 2025-03-14

Diff for: stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ def _es_config() -> Dict[str, Any]:
1616
scheme = "https" if use_ssl else "http"
1717

1818
# Configure the hosts parameter with the correct scheme
19-
hosts = [f"{scheme}://{os.getenv('ES_HOST')}:{os.getenv('ES_PORT')}"]
19+
hosts = [
20+
f"{scheme}://{host.strip()}:{os.getenv('ES_PORT')}"
21+
for host in os.getenv("ES_HOST").split(",")
22+
]
2023

2124
# Initialize the configuration dictionary
22-
config = {
25+
config: Dict[str, Any] = {
2326
"hosts": hosts,
2427
"headers": {"accept": "application/vnd.elasticsearch+json; compatible-with=7"},
2528
}
@@ -34,6 +37,10 @@ def _es_config() -> Dict[str, Any]:
3437

3538
config["headers"] = headers
3639

40+
http_compress = os.getenv("ES_HTTP_COMPRESS", "true").lower() == "true"
41+
if http_compress:
42+
config["http_compress"] = True
43+
3744
# Explicitly exclude SSL settings when not using SSL
3845
if not use_ssl:
3946
return config

Diff for: stac_fastapi/opensearch/stac_fastapi/opensearch/config.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@ def _es_config() -> Dict[str, Any]:
1515
scheme = "https" if use_ssl else "http"
1616

1717
# Configure the hosts parameter with the correct scheme
18-
hosts = [f"{scheme}://{os.getenv('ES_HOST')}:{os.getenv('ES_PORT')}"]
18+
hosts = [
19+
f"{scheme}://{host.strip()}:{os.getenv('ES_PORT')}"
20+
for host in os.getenv("ES_HOST").split(",")
21+
]
1922

2023
# Initialize the configuration dictionary
21-
config = {
24+
config: Dict[str, Any] = {
2225
"hosts": hosts,
2326
"headers": {"accept": "application/json", "Content-Type": "application/json"},
2427
}
2528

29+
http_compress = os.getenv("ES_HTTP_COMPRESS", "true").lower() == "true"
30+
if http_compress:
31+
config["http_compress"] = True
32+
2633
# Explicitly exclude SSL settings when not using SSL
2734
if not use_ssl:
2835
return config

0 commit comments

Comments
 (0)