Skip to content

Commit a63a942

Browse files
committed
feat: more configuration options for Elasticsearch/OpenSearch
1 parent b016945 commit a63a942

File tree

2 files changed

+18
-4
lines changed
  • stac_fastapi
    • elasticsearch/stac_fastapi/elasticsearch
    • opensearch/stac_fastapi/opensearch

2 files changed

+18
-4
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py

Lines changed: 9 additions & 2 deletions
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

stac_fastapi/opensearch/stac_fastapi/opensearch/config.py

Lines changed: 9 additions & 2 deletions
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)