Skip to content

Commit d39c9c7

Browse files
ignore 400 fix
1 parent afbeb20 commit d39c9c7

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,17 @@ test:
5959

6060
.PHONY: test-opensearch
6161
test-opensearch:
62-
-$(run_os) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh opensearch:9202 && cd /app/stac_fastapi/elasticsearch/tests/clients && pytest'
62+
-$(run_os) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh opensearch:9202 && cd /app/stac_fastapi/elasticsearch/tests/ && pytest'
6363
docker-compose down
6464

65-
.PHONY: run-database
66-
run-database:
65+
.PHONY: run-database-es
66+
run-database-es:
6767
docker-compose run --rm elasticsearch
6868

69+
.PHONY: run-database-os
70+
run-database-os:
71+
docker-compose run --rm opensearch
72+
6973
.PHONY: pybase-install
7074
pybase-install:
7175
pip install wheel && \

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ curl -X "GET" "http://localhost:8080/collections?limit=1&token=example_token"
8080
```shell
8181
make test
8282
```
83+
84+
```shell
85+
make test-opensearch
86+
```
8387

8488
## Ingest sample data
8589

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic/database_logic_opensearch.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
import attr
99
from opensearchpy.helpers.search import Search
10-
1110
from opensearchpy import helpers, exceptions
11+
from opensearchpy.exceptions import TransportError
12+
1213
from stac_fastapi.elasticsearch import serializers
1314
from stac_fastapi.elasticsearch.config.config_opensearch import AsyncSearchSettings
1415
from stac_fastapi.elasticsearch.config.config_opensearch import (
@@ -187,10 +188,17 @@ async def create_collection_index() -> None:
187188

188189
index = f"{COLLECTIONS_INDEX}-000001"
189190

190-
await client.indices.create(
191-
index=index,
192-
body=search_body
193-
)
191+
try:
192+
await client.indices.create(
193+
index=index,
194+
body=search_body
195+
)
196+
except TransportError as e:
197+
if e.status_code == 400:
198+
pass # Ignore 400 status codes
199+
else:
200+
raise e
201+
194202
await client.close()
195203

196204

@@ -213,10 +221,17 @@ async def create_item_index(collection_id: str):
213221
"settings":ES_ITEMS_SETTINGS,
214222
}
215223

216-
await client.indices.create(
217-
index=f"{index_by_collection_id(collection_id)}-000001",
218-
body=search_body
219-
)
224+
try:
225+
await client.indices.create(
226+
index=f"{index_name}-000001",
227+
body=search_body
228+
)
229+
except TransportError as e:
230+
if e.status_code == 400:
231+
pass # Ignore 400 status codes
232+
else:
233+
raise e
234+
220235
await client.close()
221236

222237

0 commit comments

Comments
 (0)