File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
elasticsearch/stac_fastapi/elasticsearch
opensearch/stac_fastapi/opensearch Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -574,15 +574,32 @@ async def execute_search(
574
574
)
575
575
)
576
576
577
+ count_task = asyncio .create_task (
578
+ self .client .count (
579
+ index = index_param ,
580
+ ignore_unavailable = ignore_unavailable ,
581
+ body = search .to_dict (count = True ),
582
+ )
583
+ )
584
+
577
585
try :
578
586
es_response = await search_task
579
587
except exceptions .NotFoundError :
580
588
raise NotFoundError (f"Collections '{ collection_ids } ' do not exist" )
581
589
582
- matched = es_response ["hits" ]["total" ]["value" ]
583
590
hits = es_response ["hits" ]["hits" ]
584
591
items = (hit ["_source" ] for hit in hits )
585
592
593
+ matched = es_response ["hits" ]["total" ]["value" ]
594
+ if es_response ["hits" ]["total" ]["relation" ] != "eq" :
595
+ if count_task .done ():
596
+ try :
597
+ matched = count_task .result ().get ("count" )
598
+ except Exception as e :
599
+ logger .error (f"Count task failed: { e } " )
600
+ else :
601
+ count_task .cancel ()
602
+
586
603
next_token = None
587
604
if matched > page * limit :
588
605
if hits and (sort_array := hits [- 1 ].get ("sort" )):
Original file line number Diff line number Diff line change @@ -605,14 +605,31 @@ async def execute_search(
605
605
)
606
606
)
607
607
608
+ count_task = asyncio .create_task (
609
+ self .client .count (
610
+ index = index_param ,
611
+ ignore_unavailable = ignore_unavailable ,
612
+ body = search .to_dict (count = True ),
613
+ )
614
+ )
615
+
608
616
try :
609
617
es_response = await search_task
610
618
except exceptions .NotFoundError :
611
619
raise NotFoundError (f"Collections '{ collection_ids } ' do not exist" )
612
620
613
621
hits = es_response ["hits" ]["hits" ]
614
622
items = (hit ["_source" ] for hit in hits )
623
+
615
624
matched = es_response ["hits" ]["total" ]["value" ]
625
+ if es_response ["hits" ]["total" ]["relation" ] != "eq" :
626
+ if count_task .done ():
627
+ try :
628
+ matched = count_task .result ().get ("count" )
629
+ except Exception as e :
630
+ logger .error (f"Count task failed: { e } " )
631
+ else :
632
+ count_task .cancel ()
616
633
617
634
next_token = None
618
635
if matched > page * limit :
You can’t perform that action at this time.
0 commit comments