From 604cd675643985d0b46cea0ef1dbd504d87fe3e1 Mon Sep 17 00:00:00 2001 From: Ugo Sangiorgi Date: Tue, 29 Oct 2024 08:59:32 -0500 Subject: [PATCH] fixes #1881 - composite operation failing when track_total_hits is false (#1882) * fixes composite operation failing when track_total_hits is false * adding True as default for track_total_hits * enforcing wait_for_completion_timeout = 0 so there is always an id associated with the async search * checking if total is reported (track_total_hits) * Squashed commit of the following: commit 5746dc3b4eaf3896aa20b82d4b949855061570de Author: Ugo Sangiorgi Date: Fri Oct 18 13:27:44 2024 -0500 checking if total is reported (track_total_hits) commit 69990978272ec7615a227d96882b3c6fe915c52c Author: Ugo Sangiorgi Date: Fri Oct 18 13:26:58 2024 -0500 enforcing wait_for_completion_timeout = 0 so there is always an id associated with the async search commit 1086eafdbc62541765e1d4467d202ac07690450f Author: Ugo Sangiorgi Date: Thu Oct 17 11:40:39 2024 -0500 adding True as default for track_total_hits commit 4c68e3aafbcc0647b70486a0c52c01bd66049df1 Author: Ugo Sangiorgi Date: Thu Oct 17 11:14:10 2024 -0500 fixes composite operation failing when track_total_hits is false * lint * test must include 'wait_for_completion_timeout': 0 * lint * defaulting wait_for_completion_timeout instead of enforcing * Update esrally/driver/runner.py Co-authored-by: Gareth Ellis * Update esrally/driver/runner.py Co-authored-by: Gareth Ellis * Update esrally/driver/runner.py Co-authored-by: Gareth Ellis * lint * better comment --------- Co-authored-by: Gareth Ellis --- esrally/driver/runner.py | 13 +++++++++---- tests/driver/runner_test.py | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/esrally/driver/runner.py b/esrally/driver/runner.py index 137bf4a4d..1b5018f05 100644 --- a/esrally/driver/runner.py +++ b/esrally/driver/runner.py @@ -2495,10 +2495,14 @@ def __repr__(self, *args, **kwargs): class SubmitAsyncSearch(Runner): async def __call__(self, es, params): request_params = params.get("request-params", {}) + + # defaults wait_for_completion_timeout = 0 to avoid sync fallback for fast searches + if "wait_for_completion_timeout" not in request_params: + request_params["wait_for_completion_timeout"] = 0 + response = await es.async_search.submit(body=mandatory(params, "body", self), index=params.get("index"), params=request_params) op_name = mandatory(params, "name", self) - # id may be None if the operation has already returned search_id = response.get("id") CompositeContext.put(op_name, search_id) @@ -2510,7 +2514,6 @@ def async_search_ids(op_names): subjects = [op_names] if isinstance(op_names, str) else op_names for subject in subjects: subject_id = CompositeContext.get(subject) - # skip empty ids, searches have already completed if subject_id: yield subject_id, subject @@ -2527,12 +2530,14 @@ async def __call__(self, es, params): success = success and not is_running if not is_running: stats[search] = { - "hits": response["response"]["hits"]["total"]["value"], - "hits_relation": response["response"]["hits"]["total"]["relation"], "timed_out": response["response"]["timed_out"], "took": response["response"]["took"], } + if "total" in response["response"]["hits"].keys(): + stats[search]["hits"] = response["response"]["hits"]["total"]["value"] + stats[search]["hits_relation"] = response["response"]["hits"]["total"]["relation"] + return { # only count completed searches - there is one key per search id in `stats` "weight": len(stats), diff --git a/tests/driver/runner_test.py b/tests/driver/runner_test.py index 561404752..22d60ddad 100644 --- a/tests/driver/runner_test.py +++ b/tests/driver/runner_test.py @@ -6119,7 +6119,9 @@ async def test_submit_async_search(self, es): # search id is registered in context assert runner.CompositeContext.get("search-1") == "12345" - es.async_search.submit.assert_awaited_once_with(body={"query": {"match_all": {}}}, index="_all", params={}) + es.async_search.submit.assert_awaited_once_with( + body={"query": {"match_all": {}}}, index="_all", params={"wait_for_completion_timeout": 0} + ) class TestGetAsyncSearch: