Skip to content

Commit cc143aa

Browse files
authored
Merge branch 'main' into update_stac-fastapi_2.4.8
2 parents 591d3b8 + b324592 commit cc143aa

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2020

2121
- Corrected the closing of client connections in ES index management functions [#132](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/132)
2222
- Corrected the automatic converstion of float values to int when building Filter Clauses [#135](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/135)
23+
- Remove unsupported characters from Elasticsearch index names [#153](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/153)
2324

2425
## [v0.3.0]
2526

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@
2424

2525
COLLECTIONS_INDEX = os.getenv("STAC_COLLECTIONS_INDEX", "collections")
2626
ITEMS_INDEX_PREFIX = os.getenv("STAC_ITEMS_INDEX_PREFIX", "items_")
27+
ES_INDEX_NAME_UNSUPPORTED_CHARS = {
28+
"\\",
29+
"/",
30+
"*",
31+
"?",
32+
'"',
33+
"<",
34+
">",
35+
"|",
36+
" ",
37+
",",
38+
"#",
39+
":",
40+
}
2741

2842
DEFAULT_INDICES = f"*,-*kibana*,-{COLLECTIONS_INDEX}"
2943

@@ -136,7 +150,7 @@ def index_by_collection_id(collection_id: str) -> str:
136150
Returns:
137151
str: The index name derived from the collection id.
138152
"""
139-
return f"{ITEMS_INDEX_PREFIX}{collection_id}"
153+
return f"{ITEMS_INDEX_PREFIX}{''.join(c for c in collection_id.lower() if c not in ES_INDEX_NAME_UNSUPPORTED_CHARS)}"
140154

141155

142156
def indices(collection_ids: Optional[List[str]]) -> str:
@@ -152,7 +166,7 @@ def indices(collection_ids: Optional[List[str]]) -> str:
152166
if collection_ids is None:
153167
return DEFAULT_INDICES
154168
else:
155-
return ",".join([f"{ITEMS_INDEX_PREFIX}{c.strip()}" for c in collection_ids])
169+
return ",".join([index_by_collection_id(c) for c in collection_ids])
156170

157171

158172
async def create_collection_index() -> None:

stac_fastapi/elasticsearch/tests/resources/test_item.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ async def test_create_item_missing_collection(app_client, ctx):
7575
assert resp.status_code == 404
7676

7777

78+
async def test_create_uppercase_collection_with_item(app_client, ctx, txn_client):
79+
"""Test creation of a collection and item with uppercase collection ID (transactions extension)"""
80+
collection_id = "UPPERCASE"
81+
ctx.item["collection"] = collection_id
82+
ctx.collection["id"] = collection_id
83+
resp = await app_client.post("/collections", json=ctx.collection)
84+
assert resp.status_code == 200
85+
await refresh_indices(txn_client)
86+
resp = await app_client.post(f"/collections/{collection_id}/items", json=ctx.item)
87+
assert resp.status_code == 200
88+
89+
7890
async def test_update_item_already_exists(app_client, ctx):
7991
"""Test updating an item which already exists (transactions extension)"""
8092

0 commit comments

Comments
 (0)