Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #1881 - composite operation failing when track_total_hits is false #1882

Merged
merged 15 commits into from
Oct 29, 2024
Merged
13 changes: 9 additions & 4 deletions esrally/driver/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand All @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion tests/driver/runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading