Skip to content

Commit 506a186

Browse files
committed
Added support for searching large amount of indices by moving the indices from the request url to the body of the request when size is larger than 4096 bytes.
1 parent a0b77cb commit 506a186

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
from stac_fastapi.types.stac import Collection, Item
6464

6565
logger = logging.getLogger(__name__)
66-
66+
ES_MAX_URL_LENGTH = 4096
6767

6868
async def create_index_templates() -> None:
6969
"""
@@ -546,6 +546,17 @@ async def execute_search(
546546

547547
index_param = indices(collection_ids)
548548

549+
if len(index_param) > ES_MAX_URL_LENGTH-300:
550+
index_param = ITEM_INDICES
551+
index_filter = {"terms": {"collection": collection_ids}}
552+
if not "bool" in search_body["query"]:
553+
search_body["query"]["bool"] = {}
554+
if not "filter" in search_body["query"]["bool"]:
555+
search_body["query"]["bool"]["filter"] = [index_filter]
556+
filters = search_body["query"]["bool"]["filter"]
557+
if not index_filter in filters:
558+
filters.append(index_filter)
559+
549560
max_result_window = MAX_LIMIT
550561

551562
size_limit = min(limit + 1, max_result_window)

0 commit comments

Comments
 (0)