Skip to content

Commit 37b508f

Browse files
authored
Merge branch 'main' into stac_fastapi_2.4.9
2 parents ea2294b + 67f5f03 commit 37b508f

File tree

8 files changed

+39
-22
lines changed

8 files changed

+39
-22
lines changed

.github/workflows/cicd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
services:
1717

1818
elasticsearch_8_svc:
19-
image: docker.elastic.co/elasticsearch/elasticsearch:8.10.4
19+
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.0
2020
env:
2121
cluster.name: stac-cluster
2222
node.name: es01

CHANGELOG.md

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

1212
### Changed
1313

14+
- Elasticsearch drivers from 7.17.9 to 8.11.0 [#169](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/169)
15+
1416
### Fixed
1517

1618
- Exclude unset fields in search response [#166](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/166)

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ services:
3131

3232
elasticsearch:
3333
container_name: es-container
34-
image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTICSEARCH_VERSION:-8.10.4}
34+
image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTICSEARCH_VERSION:-8.11.0}
3535
environment:
3636
ES_JAVA_OPTS: -Xms512m -Xmx1g
3737
volumes:

stac_fastapi/elasticsearch/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"stac-fastapi.types==2.4.9",
1414
"stac-fastapi.api==2.4.9",
1515
"stac-fastapi.extensions==2.4.9",
16-
"elasticsearch[async]==7.17.9",
17-
"elasticsearch-dsl==7.4.1",
16+
"elasticsearch[async]==8.11.0",
17+
"elasticsearch-dsl==8.11.0",
1818
"pystac[validation]",
1919
"uvicorn",
2020
"orjson",

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,43 @@
11
"""API configuration."""
22
import os
3+
import ssl
34
from typing import Any, Dict, Set
45

56
from elasticsearch import AsyncElasticsearch, Elasticsearch # type: ignore
67
from stac_fastapi.types.config import ApiSettings
78

89

910
def _es_config() -> Dict[str, Any]:
11+
# Determine the scheme (http or https)
12+
use_ssl = os.getenv("ES_USE_SSL", "true").lower() == "true"
13+
scheme = "https" if use_ssl else "http"
14+
15+
# Configure the hosts parameter with the correct scheme
16+
hosts = [f"{scheme}://{os.getenv('ES_HOST')}:{os.getenv('ES_PORT')}"]
17+
18+
# Initialize the configuration dictionary
1019
config = {
11-
"hosts": [{"host": os.getenv("ES_HOST"), "port": os.getenv("ES_PORT")}],
20+
"hosts": hosts,
1221
"headers": {"accept": "application/vnd.elasticsearch+json; compatible-with=7"},
13-
"use_ssl": True,
14-
"verify_certs": True,
1522
}
1623

17-
if (u := os.getenv("ES_USER")) and (p := os.getenv("ES_PASS")):
18-
config["http_auth"] = (u, p)
24+
# Explicitly exclude SSL settings when not using SSL
25+
if not use_ssl:
26+
return config
1927

20-
if (v := os.getenv("ES_USE_SSL")) and v == "false":
21-
config["use_ssl"] = False
28+
# Include SSL settings if using https
29+
config["ssl_version"] = ssl.TLSVersion.TLSv1_3 # type: ignore
30+
config["verify_certs"] = os.getenv("ES_VERIFY_CERTS", "true").lower() != "false" # type: ignore
2231

23-
if (v := os.getenv("ES_VERIFY_CERTS")) and v == "false":
24-
config["verify_certs"] = False
32+
# Include CA Certificates if verifying certs
33+
if config["verify_certs"]:
34+
config["ca_certs"] = os.getenv(
35+
"CURL_CA_BUNDLE", "/etc/ssl/certs/ca-certificates.crt"
36+
)
2537

26-
if v := os.getenv("CURL_CA_BUNDLE"):
27-
config["ca_certs"] = v
38+
# Handle authentication
39+
if (u := os.getenv("ES_USER")) and (p := os.getenv("ES_PASS")):
40+
config["http_auth"] = (u, p)
2841

2942
return config
3043

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,19 @@ def indices(collection_ids: Optional[List[str]]) -> str:
170170

171171

172172
async def create_collection_index() -> None:
173-
"""Create the index for Collections in Elasticsearch.
173+
"""
174+
Create the index for a Collection.
175+
176+
Returns:
177+
None
174178
175-
This function creates the Elasticsearch index for the `Collections` with the predefined mapping.
176-
If the index already exists, the function ignores the error and continues execution.
177179
"""
178180
client = AsyncElasticsearchSettings().create_client
179181

180-
await client.indices.create(
182+
await client.options(ignore_status=400).indices.create(
181183
index=f"{COLLECTIONS_INDEX}-000001",
182184
aliases={COLLECTIONS_INDEX: {}},
183185
mappings=ES_COLLECTIONS_MAPPINGS,
184-
ignore=400, # ignore 400 already exists code
185186
)
186187
await client.close()
187188

@@ -200,12 +201,11 @@ async def create_item_index(collection_id: str):
200201
client = AsyncElasticsearchSettings().create_client
201202
index_name = index_by_collection_id(collection_id)
202203

203-
await client.indices.create(
204+
await client.options(ignore_status=400).indices.create(
204205
index=f"{index_by_collection_id(collection_id)}-000001",
205206
aliases={index_name: {}},
206207
mappings=ES_ITEMS_MAPPINGS,
207208
settings=ES_ITEMS_SETTINGS,
208-
ignore=400, # ignore 400 already exists code
209209
)
210210
await client.close()
211211

stac_fastapi/elasticsearch/tests/api/test_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ async def test_search_polygon_intersects_get(app_client, ctx):
363363
assert len(resp_json["features"]) == 1
364364

365365

366+
@pytest.mark.asyncio
366367
async def test_search_point_intersects_post(app_client, ctx):
367368
point = [150.04, -33.14]
368369
intersects = {"type": "Point", "coordinates": point}

stac_fastapi/elasticsearch/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Config:
6565
@pytest.fixture(scope="session")
6666
def event_loop():
6767
loop = asyncio.new_event_loop()
68+
asyncio.set_event_loop(loop)
6869
yield loop
6970
loop.close()
7071

0 commit comments

Comments
 (0)