Skip to content

feat: more configuration options for Elasticsearch/OpenSearch #349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

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

### Changed

## [v3.2.4] - 2025-03-14
Expand Down
11 changes: 9 additions & 2 deletions stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ def _es_config() -> Dict[str, Any]:
scheme = "https" if use_ssl else "http"

# Configure the hosts parameter with the correct scheme
hosts = [f"{scheme}://{os.getenv('ES_HOST')}:{os.getenv('ES_PORT')}"]
hosts = [
f"{scheme}://{host.strip()}:{os.getenv('ES_PORT')}"
for host in os.getenv("ES_HOST").split(",")
]

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

config["headers"] = headers

http_compress = os.getenv("ES_HTTP_COMPRESS", "true").lower() == "true"
if http_compress:
config["http_compress"] = True

# Explicitly exclude SSL settings when not using SSL
if not use_ssl:
return config
Expand Down
11 changes: 9 additions & 2 deletions stac_fastapi/opensearch/stac_fastapi/opensearch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ def _es_config() -> Dict[str, Any]:
scheme = "https" if use_ssl else "http"

# Configure the hosts parameter with the correct scheme
hosts = [f"{scheme}://{os.getenv('ES_HOST')}:{os.getenv('ES_PORT')}"]
hosts = [
f"{scheme}://{host.strip()}:{os.getenv('ES_PORT')}"
for host in os.getenv("ES_HOST").split(",")
]

# Initialize the configuration dictionary
config = {
config: Dict[str, Any] = {
"hosts": hosts,
"headers": {"accept": "application/json", "Content-Type": "application/json"},
}

http_compress = os.getenv("ES_HTTP_COMPRESS", "true").lower() == "true"
if http_compress:
config["http_compress"] = True

# Explicitly exclude SSL settings when not using SSL
if not use_ssl:
return config
Expand Down