Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ static Request count(CountRequest countRequest) throws IOException {
params.withRouting(countRequest.routing());
params.withPreference(countRequest.preference());
params.withIndicesOptions(countRequest.indicesOptions());
if (countRequest.terminateAfter() != 0){
params.withTerminateAfter(countRequest.terminateAfter());
}
request.addParameters(params.asMap());
request.setEntity(createEntity(countRequest.source(), REQUEST_BODY_CONTENT_TYPE));
return request;
Expand Down Expand Up @@ -910,6 +913,10 @@ Params withStoredFields(String[] storedFields) {
return this;
}

Params withTerminateAfter(int terminateAfter){
return putParam("terminate_after", String.valueOf(terminateAfter));
}

Params withTimeout(TimeValue timeout) {
return putParam("timeout", timeout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.Strings;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.internal.SearchContext;

import java.util.Arrays;
import java.util.Objects;
Expand All @@ -42,6 +43,7 @@ public final class CountRequest extends ActionRequest implements IndicesRequest.
private String preference;
private SearchSourceBuilder searchSourceBuilder;
private IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS;
private int terminateAfter = SearchContext.DEFAULT_TERMINATE_AFTER;

public CountRequest() {
this.searchSourceBuilder = new SearchSourceBuilder();
Expand Down Expand Up @@ -165,11 +167,14 @@ public CountRequest minScore(Float minScore) {
}

public int terminateAfter() {
return this.searchSourceBuilder.terminateAfter();
return this.terminateAfter;
}

public CountRequest terminateAfter(int terminateAfter) {
this.searchSourceBuilder.terminateAfter(terminateAfter);
if (terminateAfter < 0) {
throw new IllegalArgumentException("terminateAfter must be > 0");
}
this.terminateAfter = terminateAfter;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,10 @@ private static void setRandomCountParams(CountRequest countRequest,
countRequest.preference(randomAlphaOfLengthBetween(3, 10));
expectedParams.put("preference", countRequest.preference());
}
if (randomBoolean()){
countRequest.terminateAfter(randomIntBetween(0, Integer.MAX_VALUE));
expectedParams.put("terminate_after", String.valueOf(countRequest.terminateAfter()));
}
}

public void testMultiSearch() throws IOException {
Expand Down