Skip to content

Commit 554005a

Browse files
Clear Elasticsearch scroll_id context.
1 parent b2b1e83 commit 554005a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

biothings/web/query/engine.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
"""
2323

2424
import asyncio
25+
import logging
2526

2627
from elasticsearch import NotFoundError, RequestError
2728
from elasticsearch.dsl import MultiSearch, Search
2829

2930
from biothings.web.query.builder import ESScrollID
3031

32+
logger = logging.getLogger(__name__)
33+
3134

3235
class ResultInterrupt(Exception):
3336
def __init__(self, data):
@@ -139,6 +142,13 @@ async def execute(self, query, **options):
139142
raise RawResultInterrupt(res)
140143

141144
if not res["hits"]["hits"]:
145+
scroll_id = str(query.data) if query.data else "None"
146+
try:
147+
await self.client.clear_scroll(scroll_id=query.data)
148+
logger.info("Scroll context cleared: %s", scroll_id)
149+
except Exception as e:
150+
logger.warning("Failed to clear scroll context (ID: %s): %s", scroll_id, str(e))
151+
# Always raise this exception regardless of whether clear_scroll succeeds
142152
raise EndScrollInterrupt()
143153

144154
return res

0 commit comments

Comments
 (0)