Skip to content

Commit 1c48214

Browse files
authored
Async search: rename REST parameters (#54198)
This commit renames wait_for_completion to wait_for_completion_timeout in submit async search and get async search. Also it renames clean_on_completion to keep_on_completion and turns around its behaviour. Closes #54069
1 parent a65e95e commit 1c48214

File tree

16 files changed

+87
-86
lines changed

16 files changed

+87
-86
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/AsyncSearchRequestConverters.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ static Request submitAsyncSearch(SubmitAsyncSearchRequest asyncSearchRequest) th
4747
request.setEntity(RequestConverters.createEntity(asyncSearchRequest.getSearchSource(), REQUEST_BODY_CONTENT_TYPE));
4848
}
4949
// set async search submit specific parameters
50-
if (asyncSearchRequest.isCleanOnCompletion() != null) {
51-
params.putParam("clean_on_completion", asyncSearchRequest.isCleanOnCompletion().toString());
50+
if (asyncSearchRequest.isKeepOnCompletion() != null) {
51+
params.putParam("keep_on_completion", asyncSearchRequest.isKeepOnCompletion().toString());
5252
}
5353
if (asyncSearchRequest.getKeepAlive() != null) {
5454
params.putParam("keep_alive", asyncSearchRequest.getKeepAlive().getStringRep());
5555
}
56-
if (asyncSearchRequest.getWaitForCompletion() != null) {
57-
params.putParam("wait_for_completion", asyncSearchRequest.getWaitForCompletion().getStringRep());
56+
if (asyncSearchRequest.getWaitForCompletionTimeout() != null) {
57+
params.putParam("wait_for_completion_timeout", asyncSearchRequest.getWaitForCompletionTimeout().getStringRep());
5858
}
5959
request.addParameters(params.asMap());
6060
return request;
@@ -76,7 +76,7 @@ static void addSearchRequestParams(Params params, SubmitAsyncSearchRequest reque
7676
params.withBatchedReduceSize(request.getBatchedReduceSize());
7777
}
7878

79-
static Request getAsyncSearch(GetAsyncSearchRequest asyncSearchRequest) throws IOException {
79+
static Request getAsyncSearch(GetAsyncSearchRequest asyncSearchRequest) {
8080
String endpoint = new RequestConverters.EndpointBuilder()
8181
.addPathPartAsIs("_async_search")
8282
.addPathPart(asyncSearchRequest.getId())
@@ -87,13 +87,13 @@ static Request getAsyncSearch(GetAsyncSearchRequest asyncSearchRequest) throws I
8787
params.putParam("keep_alive", asyncSearchRequest.getKeepAlive().getStringRep());
8888
}
8989
if (asyncSearchRequest.getWaitForCompletion() != null) {
90-
params.putParam("wait_for_completion", asyncSearchRequest.getWaitForCompletion().getStringRep());
90+
params.putParam("wait_for_completion_timeout", asyncSearchRequest.getWaitForCompletion().getStringRep());
9191
}
9292
request.addParameters(params.asMap());
9393
return request;
9494
}
9595

96-
static Request deleteAsyncSearch(DeleteAsyncSearchRequest deleteAsyncSearchRequest) throws IOException {
96+
static Request deleteAsyncSearch(DeleteAsyncSearchRequest deleteAsyncSearchRequest) {
9797
String endpoint = new RequestConverters.EndpointBuilder()
9898
.addPathPartAsIs("_async_search")
9999
.addPathPart(deleteAsyncSearchRequest.getId())

client/rest-high-level/src/main/java/org/elasticsearch/client/asyncsearch/SubmitAsyncSearchRequest.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public class SubmitAsyncSearchRequest implements Validatable {
4343

4444
public static long MIN_KEEP_ALIVE = TimeValue.timeValueMinutes(1).millis();
4545

46-
private TimeValue waitForCompletion;
47-
private Boolean cleanOnCompletion;
46+
private TimeValue waitForCompletionTimeout;
47+
private Boolean keepOnCompletion;
4848
private TimeValue keepAlive;
4949
private final SearchRequest searchRequest;
5050

@@ -70,29 +70,29 @@ public String[] getIndices() {
7070
/**
7171
* Get the minimum time that the request should wait before returning a partial result (defaults to 1 second).
7272
*/
73-
public TimeValue getWaitForCompletion() {
74-
return waitForCompletion;
73+
public TimeValue getWaitForCompletionTimeout() {
74+
return waitForCompletionTimeout;
7575
}
7676

7777
/**
7878
* Sets the minimum time that the request should wait before returning a partial result (defaults to 1 second).
7979
*/
80-
public void setWaitForCompletion(TimeValue waitForCompletion) {
81-
this.waitForCompletion = waitForCompletion;
80+
public void setWaitForCompletionTimeout(TimeValue waitForCompletionTimeout) {
81+
this.waitForCompletionTimeout = waitForCompletionTimeout;
8282
}
8383

8484
/**
8585
* Returns whether the resource resource should be removed on completion or failure (defaults to true).
8686
*/
87-
public Boolean isCleanOnCompletion() {
88-
return cleanOnCompletion;
87+
public Boolean isKeepOnCompletion() {
88+
return keepOnCompletion;
8989
}
9090

9191
/**
9292
* Determines if the resource should be removed on completion or failure (defaults to true).
9393
*/
94-
public void setCleanOnCompletion(boolean cleanOnCompletion) {
95-
this.cleanOnCompletion = cleanOnCompletion;
94+
public void setKeepOnCompletion(boolean keepOnCompletion) {
95+
this.keepOnCompletion = keepOnCompletion;
9696
}
9797

9898
/**
@@ -273,12 +273,12 @@ public boolean equals(Object o) {
273273
SubmitAsyncSearchRequest request = (SubmitAsyncSearchRequest) o;
274274
return Objects.equals(searchRequest, request.searchRequest)
275275
&& Objects.equals(getKeepAlive(), request.getKeepAlive())
276-
&& Objects.equals(getWaitForCompletion(), request.getWaitForCompletion())
277-
&& Objects.equals(isCleanOnCompletion(), request.isCleanOnCompletion());
276+
&& Objects.equals(getWaitForCompletionTimeout(), request.getWaitForCompletionTimeout())
277+
&& Objects.equals(isKeepOnCompletion(), request.isKeepOnCompletion());
278278
}
279279

280280
@Override
281281
public int hashCode() {
282-
return Objects.hash(searchRequest, getKeepAlive(), getWaitForCompletion(), isCleanOnCompletion());
282+
return Objects.hash(searchRequest, getKeepAlive(), getWaitForCompletionTimeout(), isKeepOnCompletion());
283283
}
284284
}

client/rest-high-level/src/test/java/org/elasticsearch/client/AsyncSearchRequestConvertersTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ public void testSubmitAsyncSearch() throws Exception {
5656
setRandomIndicesOptions(submitRequest::setIndicesOptions, submitRequest::getIndicesOptions, expectedParams);
5757

5858
if (randomBoolean()) {
59-
boolean cleanOnCompletion = randomBoolean();
60-
submitRequest.setCleanOnCompletion(cleanOnCompletion);
61-
expectedParams.put("clean_on_completion", Boolean.toString(cleanOnCompletion));
59+
boolean keepOnCompletion = randomBoolean();
60+
submitRequest.setKeepOnCompletion(keepOnCompletion);
61+
expectedParams.put("keep_on_completion", Boolean.toString(keepOnCompletion));
6262
}
6363
if (randomBoolean()) {
6464
TimeValue keepAlive = TimeValue.parseTimeValue(randomTimeValue(), "test");
6565
submitRequest.setKeepAlive(keepAlive);
6666
expectedParams.put("keep_alive", keepAlive.getStringRep());
6767
}
6868
if (randomBoolean()) {
69-
TimeValue waitForCompletion = TimeValue.parseTimeValue(randomTimeValue(), "test");
70-
submitRequest.setWaitForCompletion(waitForCompletion);
71-
expectedParams.put("wait_for_completion", waitForCompletion.getStringRep());
69+
TimeValue waitForCompletionTimeout = TimeValue.parseTimeValue(randomTimeValue(), "test");
70+
submitRequest.setWaitForCompletionTimeout(waitForCompletionTimeout);
71+
expectedParams.put("wait_for_completion_timeout", waitForCompletionTimeout.getStringRep());
7272
}
7373

7474
Request request = AsyncSearchRequestConverters.submitAsyncSearch(submitRequest);
@@ -128,7 +128,7 @@ public void testGetAsyncSearch() throws Exception {
128128
if (randomBoolean()) {
129129
TimeValue waitForCompletion = TimeValue.parseTimeValue(randomTimeValue(), "test");
130130
submitRequest.setWaitForCompletion(waitForCompletion);
131-
expectedParams.put("wait_for_completion", waitForCompletion.getStringRep());
131+
expectedParams.put("wait_for_completion_timeout", waitForCompletion.getStringRep());
132132
}
133133

134134
Request request = AsyncSearchRequestConverters.getAsyncSearch(submitRequest);

client/rest-high-level/src/test/java/org/elasticsearch/client/asyncsearch/AsyncSearchIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void testAsyncSearch() throws IOException {
3636

3737
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder().query(QueryBuilders.matchAllQuery());
3838
SubmitAsyncSearchRequest submitRequest = new SubmitAsyncSearchRequest(sourceBuilder, index);
39-
submitRequest.setCleanOnCompletion(false);
39+
submitRequest.setKeepOnCompletion(true);
4040
AsyncSearchResponse submitResponse = highLevelClient().asyncSearch().submit(submitRequest, RequestOptions.DEFAULT);
4141
assertNotNull(submitResponse.getId());
4242
assertFalse(submitResponse.isPartial());

docs/reference/search/async-search.asciidoc

+9-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ POST /sales*/_async_search?size=0
3131
}
3232
--------------------------------------------------
3333
// TEST[setup:sales]
34-
// TEST[s/size=0/size=0&wait_for_completion=10s&clean_on_completion=false/]
34+
// TEST[s/size=0/size=0&wait_for_completion_timeout=10s&keep_on_completion=true/]
3535

3636
The response contains an identifier of the search being executed.
3737
You can use this ID to later retrieve the search's final results.
@@ -88,8 +88,8 @@ results are returned as part of the <<search-api-response-body,`response`>> obje
8888
<6> How many documents are currently matching the query, which belong to the shards that have already completed the search
8989

9090
It is possible to block and wait until the search is completed up to a certain
91-
timeout by providing the `wait_for_completion` parameter, which defaults to
92-
`1` second.
91+
timeout by providing the `wait_for_completion_timeout` parameter, which
92+
defaults to `1` second.
9393

9494
You can also specify how long the async search needs to be
9595
available through the `keep_alive` parameter, which defaults to `5d` (five days).
@@ -193,11 +193,12 @@ first.
193193
<6> Partial aggregations results, coming from the shards that have already
194194
completed the execution of the query.
195195

196-
The `wait_for_completion` parameter, which defaults to `1`, can also be provided
197-
when calling the Get Async Search API, in order to wait for the search to be
198-
completed up until the provided timeout. Final results will be returned if
199-
available before the timeout expires, otherwise the currently available results
200-
will be returned once the timeout expires.
196+
The `wait_for_completion_timeout` parameter can also be provided when calling
197+
the Get Async Search API, in order to wait for the search to be completed up
198+
until the provided timeout. Final results will be returned if available before
199+
the timeout expires, otherwise the currently available results will be
200+
returned once the timeout expires. By default no timeout is set meaning that
201+
the currently available results will be returned without any additional wait.
201202

202203
The `keep_alive` parameter specifies how long the async search should be
203204
available in the cluster. When not specified, the `keep_alive` set with the

x-pack/plugin/async-search/qa/security/src/test/java/org/elasticsearch/xpack/search/AsyncSearchSecurityIT.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,16 @@ static Response submitAsyncSearch(String indexName, String query, TimeValue wait
127127
final Request request = new Request("POST", indexName + "/_async_search");
128128
setRunAsHeader(request, user);
129129
request.addParameter("q", query);
130-
request.addParameter("wait_for_completion", waitForCompletion.toString());
130+
request.addParameter("wait_for_completion_timeout", waitForCompletion.toString());
131131
// we do the cleanup explicitly
132-
request.addParameter("clean_on_completion", "false");
132+
request.addParameter("keep_on_completion", "true");
133133
return client().performRequest(request);
134134
}
135135

136136
static Response getAsyncSearch(String id, String user) throws IOException {
137137
final Request request = new Request("GET", "/_async_search/" + id);
138138
setRunAsHeader(request, user);
139-
request.addParameter("wait_for_completion", "0ms");
139+
request.addParameter("wait_for_completion_timeout", "0ms");
140140
return client().performRequest(request);
141141
}
142142

x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/RestGetAsyncSearchAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public String getName() {
3434
@Override
3535
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) {
3636
GetAsyncSearchAction.Request get = new GetAsyncSearchAction.Request(request.param("id"));
37-
if (request.hasParam("wait_for_completion")) {
38-
get.setWaitForCompletion(request.paramAsTime("wait_for_completion", get.getWaitForCompletion()));
37+
if (request.hasParam("wait_for_completion_timeout")) {
38+
get.setWaitForCompletion(request.paramAsTime("wait_for_completion_timeout", get.getWaitForCompletion()));
3939
}
4040
if (request.hasParam("keep_alive")) {
4141
get.setKeepAlive(request.paramAsTime("keep_alive", get.getKeepAlive()));

x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/RestSubmitAsyncSearchAction.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
5151
request.withContentOrSourceParamParserOrNull(parser ->
5252
parseSearchRequest(submit.getSearchRequest(), request, parser, setSize));
5353

54-
if (request.hasParam("wait_for_completion")) {
55-
submit.setWaitForCompletion(request.paramAsTime("wait_for_completion", submit.getWaitForCompletion()));
54+
if (request.hasParam("wait_for_completion_timeout")) {
55+
submit.setWaitForCompletionTimeout(request.paramAsTime("wait_for_completion_timeout", submit.getWaitForCompletionTimeout()));
5656
}
5757
if (request.hasParam("keep_alive")) {
5858
submit.setKeepAlive(request.paramAsTime("keep_alive", submit.getKeepAlive()));
5959
}
60-
if (request.hasParam("clean_on_completion")) {
61-
submit.setCleanOnCompletion(request.paramAsBoolean("clean_on_completion", submit.isCleanOnCompletion()));
60+
if (request.hasParam("keep_on_completion")) {
61+
submit.setKeepOnCompletion(request.paramAsBoolean("keep_on_completion", submit.isKeepOnCompletion()));
6262
}
6363
return channel -> {
6464
RestStatusToXContentListener<AsyncSearchResponse> listener = new RestStatusToXContentListener<>(channel);

x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/TransportSubmitAsyncSearchAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected void doExecute(Task task, SubmitAsyncSearchRequest request, ActionList
7373
new ActionListener<>() {
7474
@Override
7575
public void onResponse(AsyncSearchResponse searchResponse) {
76-
if (searchResponse.isRunning() || request.isCleanOnCompletion() == false) {
76+
if (searchResponse.isRunning() || request.isKeepOnCompletion()) {
7777
// the task is still running and the user cannot wait more so we create
7878
// a document for further retrieval
7979
try {
@@ -126,7 +126,7 @@ public void onFailure(Exception exc) {
126126
public void onFailure(Exception exc) {
127127
submitListener.onFailure(exc);
128128
}
129-
}, request.getWaitForCompletion());
129+
}, request.getWaitForCompletionTimeout());
130130
}
131131

132132
private SearchRequest createSearchRequest(SubmitAsyncSearchRequest request, CancellableTask submitTask, TimeValue keepAlive) {

x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchActionTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ public void testInvalidId() throws Exception {
238238

239239
public void testNoIndex() throws Exception {
240240
SubmitAsyncSearchRequest request = new SubmitAsyncSearchRequest("invalid-*");
241-
request.setWaitForCompletion(TimeValue.timeValueMillis(1));
241+
request.setWaitForCompletionTimeout(TimeValue.timeValueMillis(1));
242242
AsyncSearchResponse response = submitAsyncSearch(request);
243243
assertNotNull(response.getSearchResponse());
244244
assertFalse(response.isRunning());
245245
assertThat(response.getSearchResponse().getTotalShards(), equalTo(0));
246246

247247
request = new SubmitAsyncSearchRequest("invalid");
248-
request.setWaitForCompletion(TimeValue.timeValueMillis(1));
248+
request.setWaitForCompletionTimeout(TimeValue.timeValueMillis(1));
249249
response = submitAsyncSearch(request);
250250
assertNull(response.getSearchResponse());
251251
assertNotNull(response.getFailure());
@@ -259,7 +259,7 @@ public void testCancellation() throws Exception {
259259
request.getSearchRequest().source(
260260
new SearchSourceBuilder().aggregation(new CancellingAggregationBuilder("test"))
261261
);
262-
request.setWaitForCompletion(TimeValue.timeValueMillis(1));
262+
request.setWaitForCompletionTimeout(TimeValue.timeValueMillis(1));
263263
AsyncSearchResponse response = submitAsyncSearch(request);
264264
assertNotNull(response.getSearchResponse());
265265
assertTrue(response.isRunning());

x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchIntegTestCase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ protected SearchResponseIterator assertBlockingIterator(String indexName,
125125
int progressStep) throws Exception {
126126
SubmitAsyncSearchRequest request = new SubmitAsyncSearchRequest(source, indexName);
127127
request.setBatchedReduceSize(progressStep);
128-
request.setWaitForCompletion(TimeValue.timeValueMillis(1));
128+
request.setWaitForCompletionTimeout(TimeValue.timeValueMillis(1));
129129
ClusterSearchShardsResponse response = dataNodeClient().admin().cluster()
130130
.prepareSearchShards(request.getSearchRequest().indices()).get();
131131
AtomicInteger failures = new AtomicInteger(numFailures);

x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/SubmitAsyncSearchRequestTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ protected SubmitAsyncSearchRequest createTestInstance() {
3535
searchRequest = new SubmitAsyncSearchRequest();
3636
}
3737
if (randomBoolean()) {
38-
searchRequest.setWaitForCompletion(TimeValue.parseTimeValue(randomPositiveTimeValue(), "wait_for_completion"));
38+
searchRequest.setWaitForCompletionTimeout(TimeValue.parseTimeValue(randomPositiveTimeValue(), "wait_for_completion"));
3939
}
40-
searchRequest.setCleanOnCompletion(randomBoolean());
40+
searchRequest.setKeepOnCompletion(randomBoolean());
4141
if (randomBoolean()) {
4242
searchRequest.setKeepAlive(TimeValue.parseTimeValue(randomPositiveTimeValue(), "keep_alive"));
4343
}

0 commit comments

Comments
 (0)