Skip to content

Commit a31ae02

Browse files
[8.0] Always set 'sort' and 'scroll' for scan helper
Co-authored-by: Seth Michael Larson <seth.larson@elastic.co>
1 parent 0f09355 commit a31ae02

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

elasticsearch/_async/helpers.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,19 @@ def pop_transport_kwargs(kw):
355355
)
356356
client._client_meta = (("h", "s"),)
357357

358-
# initial search
359-
search_kwargs = query.copy() if query else {}
360-
search_kwargs.update(kwargs)
361-
search_kwargs["scroll"] = scroll
362-
search_kwargs["size"] = size
363-
364358
try:
359+
search_kwargs = query.copy() if query else {}
360+
search_kwargs.update(kwargs)
361+
search_kwargs["scroll"] = scroll
362+
search_kwargs["size"] = size
365363
resp = await client.search(**search_kwargs)
364+
365+
# Try the old deprecated way if we fail immediately on parameters.
366366
except TypeError:
367-
resp = await client.search(body=query, scroll=scroll, size=size, **kwargs)
367+
search_kwargs = kwargs.copy()
368+
search_kwargs["scroll"] = scroll
369+
search_kwargs["size"] = size
370+
resp = await client.search(body=query, **search_kwargs)
368371

369372
scroll_id = resp.raw.get("_scroll_id")
370373
scroll_transport_kwargs = pop_transport_kwargs(scroll_kwargs)

elasticsearch/helpers/actions.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,15 +566,20 @@ def pop_transport_kwargs(kw):
566566
)
567567
client._client_meta = (("h", "s"),)
568568

569-
# initial search
570-
search_kwargs = query.copy() if query else {}
571-
search_kwargs.update(kwargs)
572-
search_kwargs["scroll"] = scroll
573-
search_kwargs["size"] = size
574569
try:
570+
search_kwargs = query.copy() if query else {}
571+
search_kwargs.update(kwargs)
572+
search_kwargs["scroll"] = scroll
573+
search_kwargs["size"] = size
575574
resp = client.search(**search_kwargs)
575+
576+
# Try the old deprecated way if we fail immediately on parameters.
576577
except TypeError:
577-
resp = client.search(body=query, scroll=scroll, size=size, **kwargs)
578+
search_kwargs = kwargs.copy()
579+
search_kwargs["scroll"] = scroll
580+
search_kwargs["size"] = size
581+
resp = client.search(body=query, **search_kwargs)
582+
578583
scroll_id = resp.raw.get("_scroll_id")
579584
scroll_transport_kwargs = pop_transport_kwargs(scroll_kwargs)
580585
if scroll_transport_kwargs:

test_elasticsearch/test_async/test_server/test_rest_api_spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ async def run_do(self, action):
147147
warnings.simplefilter("always", category=ElasticsearchWarning)
148148
with warnings.catch_warnings(record=True) as caught_warnings:
149149
try:
150-
self.last_response = await api(**args).raw
150+
self.last_response = (await api(**args)).raw
151151
except Exception as e:
152152
if not catch:
153153
raise

0 commit comments

Comments
 (0)