diff --git a/x-pack/plugin/fleet/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/fleet/20_wait_for_checkpoints.yml b/x-pack/plugin/fleet/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/fleet/20_wait_for_checkpoints.yml index 7637e7cce4cf3..5610502a65d23 100644 --- a/x-pack/plugin/fleet/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/fleet/20_wait_for_checkpoints.yml +++ b/x-pack/plugin/fleet/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/fleet/20_wait_for_checkpoints.yml @@ -32,6 +32,28 @@ setup: - do: indices.refresh: {} +--- +"Execute successful search with wait_for_checkpoints default": + - do: + fleet.search: + index: "test-after-refresh" + allow_partial_search_results: false + + body: { query: { match_all: {} } } + + - match: { _shards.successful: 1 } + - match: { hits.total.value: 2 } + + - do: + fleet.search: + index: "test-after-refresh" + allow_partial_search_results: false + wait_for_checkpoints: [] + body: { query: { match_all: { } } } + + - match: { _shards.successful: 1 } + - match: { hits.total.value: 2 } + --- "Execute successful after refresh search": - do: @@ -114,3 +136,19 @@ setup: - match: { responses.1._shards.successful: 1 } - match: { responses.1.hits.total.value: 2 } - match: { responses.2.error.caused_by.type: "illegal_argument_exception" } + +--- +"Test msearch wait_for_checkpoints default": + - do: + fleet.msearch: + index: "test-after-refresh" + body: + - { "allow_partial_search_results": false } + - { query: { match_all: { } } } + - { "allow_partial_search_results": false, wait_for_checkpoints: [] } + - { query: { match_all: { } } } + + - match: { responses.0._shards.successful: 1 } + - match: { responses.0.hits.total.value: 2 } + - match: { responses.1._shards.successful: 1 } + - match: { responses.1.hits.total.value: 2 } diff --git a/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/rest/RestFleetMultiSearchAction.java b/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/rest/RestFleetMultiSearchAction.java index 0147267cb3023..b9c208da927d5 100644 --- a/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/rest/RestFleetMultiSearchAction.java +++ b/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/rest/RestFleetMultiSearchAction.java @@ -68,7 +68,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli for (int i = 0; i < stringWaitForCheckpoints.length; ++i) { waitForCheckpoints[i] = Long.parseLong(stringWaitForCheckpoints[i]); } - searchRequest.setWaitForCheckpoints(Collections.singletonMap("*", waitForCheckpoints)); + if (waitForCheckpoints.length != 0) { + searchRequest.setWaitForCheckpoints(Collections.singletonMap("*", waitForCheckpoints)); + } return true; } else if ("wait_for_checkpoints_timeout".equals(key)) { final TimeValue waitForCheckpointsTimeout = nodeTimeValue(value, TimeValue.timeValueSeconds(30)); @@ -96,7 +98,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli } } long[] checkpoints = searchRequest.getWaitForCheckpoints().get("*"); - searchRequest.setWaitForCheckpoints(Collections.singletonMap(indices[0], checkpoints)); + if (checkpoints != null) { + searchRequest.setWaitForCheckpoints(Collections.singletonMap(indices[0], checkpoints)); + } } return channel -> { diff --git a/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/rest/RestFleetSearchAction.java b/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/rest/RestFleetSearchAction.java index fdee70c38cdd2..e583b28429134 100644 --- a/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/rest/RestFleetSearchAction.java +++ b/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/rest/RestFleetSearchAction.java @@ -76,7 +76,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli "Fleet search API only supports searching a single index. Found: [" + Arrays.toString(indices1) + "]." ); } - sr.setWaitForCheckpoints(Collections.singletonMap(indices1[0], waitForCheckpoints)); + if (waitForCheckpoints.length != 0) { + sr.setWaitForCheckpoints(Collections.singletonMap(indices1[0], waitForCheckpoints)); + } final TimeValue waitForCheckpointsTimeout = request.paramAsTime( "wait_for_checkpoints_timeout", TimeValue.timeValueSeconds(30)