From a63a942e4dbc5965c2c9856c9e9f9d9fbb7ca92c Mon Sep 17 00:00:00 2001 From: Stijn Caerts Date: Tue, 1 Apr 2025 12:20:35 +0200 Subject: [PATCH 1/2] feat: more configuration options for Elasticsearch/OpenSearch --- .../stac_fastapi/elasticsearch/config.py | 11 +++++++++-- .../opensearch/stac_fastapi/opensearch/config.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py index 40318860..80ac7e6b 100644 --- a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py +++ b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py @@ -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"}, } @@ -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 diff --git a/stac_fastapi/opensearch/stac_fastapi/opensearch/config.py b/stac_fastapi/opensearch/stac_fastapi/opensearch/config.py index 3104213d..ac009f5c 100644 --- a/stac_fastapi/opensearch/stac_fastapi/opensearch/config.py +++ b/stac_fastapi/opensearch/stac_fastapi/opensearch/config.py @@ -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 From 7e89ee3d5e8ec0a9b677bc3f373029ea482c5e3a Mon Sep 17 00:00:00 2001 From: Stijn Caerts Date: Tue, 1 Apr 2025 13:22:23 +0200 Subject: [PATCH 2/2] update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8830459b..98c24ab3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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