Skip to content

Commit 9d6a16e

Browse files
sort body param, cicd
1 parent d39c9c7 commit 9d6a16e

File tree

6 files changed

+55
-30
lines changed

6 files changed

+55
-30
lines changed

.github/workflows/cicd.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ jobs:
4646
ES_JAVA_OPTS: -Xms512m -Xmx1g
4747
ports:
4848
- 9400:9400
49+
50+
opensearch_2_11:
51+
image: opensearchproject/opensearch:2.11.1
52+
env:
53+
cluster.name: stac-cluster
54+
node.name: os01
55+
network.host: 0.0.0.0
56+
transport.host: 0.0.0.0
57+
discovery.type: single-node
58+
http.port: 9202
59+
http.cors.enabled: true
60+
plugins.security.disabled: true
61+
plugins.security.ssl.http.enabled: true
62+
OPENSEARCH_JAVA_OPTS: -Xms512m -Xmx512m
63+
ports:
64+
- 9202:9202
4965
strategy:
5066
matrix:
5167
python-version: [ "3.8", "3.9", "3.10", "3.11"]
@@ -90,4 +106,15 @@ jobs:
90106
ES_PORT: 9400
91107
ES_HOST: 172.17.0.1
92108
ES_USE_SSL: false
93-
ES_VERIFY_CERTS: false
109+
ES_VERIFY_CERTS: false
110+
111+
- name: Run test suite against OpenSearch 2.11.1
112+
run: |
113+
cd stac_fastapi/elasticsearch && pipenv run pytest -svvv
114+
env:
115+
ENVIRONMENT: testing
116+
ES_PORT: 9202
117+
ES_HOST: 172.17.0.1
118+
ES_USE_SSL: false
119+
ES_VERIFY_CERTS: false
120+
BACKEND: opensearch

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ docker-run: image-dev
5252
docker-shell:
5353
$(run_es) /bin/bash
5454

55-
.PHONY: test
55+
.PHONY: test-elasticsearch
5656
test:
5757
-$(run_es) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh elasticsearch:9200 && cd /app/stac_fastapi/elasticsearch/tests/ && pytest'
5858
docker-compose down
@@ -62,6 +62,14 @@ test-opensearch:
6262
-$(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: test
66+
test:
67+
-$(run_es) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh elasticsearch:9200 && cd /app/stac_fastapi/elasticsearch/tests/ && pytest'
68+
docker-compose down
69+
70+
-$(run_os) /bin/bash -c 'export && ./scripts/wait-for-it-es.sh opensearch:9202 && cd /app/stac_fastapi/elasticsearch/tests/ && pytest'
71+
docker-compose down
72+
6573
.PHONY: run-database-es
6674
run-database-es:
6775
docker-compose run --rm elasticsearch

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,19 @@ curl -X "GET" "http://localhost:8080/collections?limit=1&token=example_token"
8080
```shell
8181
make test
8282
```
83+
Test against OpenSearch only
8384

8485
```shell
8586
make test-opensearch
8687
```
87-
88+
89+
Test against Elasticsearch only
90+
91+
```shell
92+
make test-elasticsearch
93+
```
94+
95+
8896
## Ingest sample data
8997

9098
```shell

opensearch/config/opensearch.yml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,3 @@ plugins.security.disabled: true
1717
plugins.security.ssl.http.enabled: true
1818

1919
node.max_local_storage_nodes: 3
20-
21-
######## Start OpenSearch Security Demo Configuration ########
22-
# WARNING: revise all the lines below before you go into production
23-
# plugins.security.ssl.transport.pemcert_filepath: esnode.pem
24-
# plugins.security.ssl.transport.pemkey_filepath: esnode-key.pem
25-
# plugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.pem
26-
# plugins.security.ssl.transport.enforce_hostname_verification: false
27-
# plugins.security.ssl.http.pemcert_filepath: esnode.pem
28-
# plugins.security.ssl.http.pemkey_filepath: esnode-key.pem
29-
# plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.pem
30-
# plugins.security.allow_unsafe_democertificates: true
31-
# plugins.security.allow_default_init_securityindex: true
32-
# plugins.security.authcz.admin_dn:
33-
# - CN=kirk,OU=client,O=client,L=test, C=de
34-
35-
# plugins.security.audit.type: internal_opensearch
36-
# plugins.security.enable_snapshot_restore_privilege: true
37-
# plugins.security.check_snapshot_restore_write_privileges: true
38-
# plugins.security.restapi.roles_enabled: ["all_access", "security_rest_api_access"]
39-
# plugins.security.system_indices.enabled: true
40-
# plugins.security.system_indices.indices: [".plugins-ml-config", ".plugins-ml-connector", ".plugins-ml-model-group", ".plugins-ml-model", ".plugins-ml-task", ".plugins-ml-conversation-meta", ".plugins-ml-conversation-interactions", ".opendistro-alerting-config", ".opendistro-alerting-alert*", ".opendistro-anomaly-results*", ".opendistro-anomaly-detector*", ".opendistro-anomaly-checkpoints", ".opendistro-anomaly-detection-state", ".opendistro-reports-*", ".opensearch-notifications-*", ".opensearch-notebooks", ".opensearch-observability", ".ql-datasources", ".opendistro-asynchronous-search-response*", ".replication-metadata-store", ".opensearch-knn-models", ".geospatial-ip2geo-data*"]
41-
######## End OpenSearch Security Demo Configuration ########

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ async def all_collections(self, **kwargs) -> Collections:
110110
next_link = None
111111
if len(hits) == limit:
112112
last_hit = hits[-1]
113+
logger.info(last_hit)
113114
next_search_after = last_hit["sort"]
114115
next_token = urlsafe_b64encode(
115116
",".join(map(str, next_search_after)).encode()

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

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

88
import attr
99
from opensearchpy.helpers.search import Search
10+
from opensearchpy.helpers.query import Q
1011
from opensearchpy import helpers, exceptions
1112
from opensearchpy.exceptions import TransportError
1213

@@ -336,11 +337,12 @@ async def get_all_collections(
336337
if token:
337338
search_after = urlsafe_b64decode(token.encode()).decode().split(",")
338339
search_body["search_after"] = search_after
340+
search_body["sort"] = {"id": {"order": "asc"}}
341+
339342
collections = await self.client.search(
340343
index=COLLECTIONS_INDEX,
341344
body=search_body,
342-
size=limit,
343-
sort={"id": {"order": "asc"}},
345+
size=limit
344346
)
345347
hits = collections["hits"]["hits"]
346348
return hits
@@ -545,10 +547,12 @@ async def execute_search(
545547
"""
546548
search_body = {}
547549
query = search.query.to_dict() if search.query else None
548-
search_body["query"] = query if query else {}
550+
if query:
551+
search_body["query"] = query
549552
if token:
550553
search_after = urlsafe_b64decode(token.encode()).decode().split(",")
551554
search_body["search_after"] = search_after
555+
search_body["sort"] = sort if sort else DEFAULT_SORT
552556

553557
index_param = indices(collection_ids)
554558

@@ -557,8 +561,7 @@ async def execute_search(
557561
index=index_param,
558562
ignore_unavailable=ignore_unavailable,
559563
body=search_body,
560-
sort=sort or DEFAULT_SORT,
561-
size=limit,
564+
size=limit
562565
)
563566
)
564567

0 commit comments

Comments
 (0)