Skip to content

[Rest Compatible Api] update and delete by query using size field #69606

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

Merged
merged 4 commits into from
Mar 15, 2021
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
11 changes: 3 additions & 8 deletions modules/reindex/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,11 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {

tasks.named("yamlRestCompatTest").configure {
systemProperty 'tests.rest.blacklist', [
'reindex/20_validation/reindex without source gives useful error message', /* type in exception message */
'reindex/85_scripting/Reindex all docs with one doc deletion', /*type in a request*/
'delete_by_query/10_basic/Limit by size',
/*type related failures */
'reindex/20_validation/reindex without source gives useful error message',
'reindex/85_scripting/Reindex all docs with one doc deletion',
'delete_by_query/10_basic/Response for version conflict (seq no powered)',
'delete_by_query/20_validation/both max_docs and size fails',
'delete_by_query/20_validation/invalid size fails',
'update_by_query/10_basic/Limit by size',
'update_by_query/10_basic/Response for version conflict (seq no powered)',
'update_by_query/20_validation/inconsistent max_docs and size fails',
'update_by_query/20_validation/invalid size fails',
'update_by_query/20_validation/update_by_query without source gives useful error message'
].join(',')
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.common.RestApiVersion;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
Expand All @@ -21,6 +23,7 @@
import java.io.IOException;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.IntConsumer;

/**
* Rest handler for reindex actions that accepts a search request like Update-By-Query or Delete-By-Query
Expand All @@ -41,7 +44,10 @@ protected void parseInternalRequest(Request internal, RestRequest restRequest, N
SearchRequest searchRequest = internal.getSearchRequest();

try (XContentParser parser = extractRequestSpecificFields(restRequest, bodyConsumers)) {
RestSearchAction.parseSearchRequest(searchRequest, restRequest, parser, namedWriteableRegistry, size -> failOnSizeSpecified());
IntConsumer sizeConsumer = restRequest.getRestApiVersion() == RestApiVersion.V_7 ?
size -> setMaxDocsFromSearchSize(internal, size) :
size -> failOnSizeSpecified();
RestSearchAction.parseSearchRequest(searchRequest, restRequest, parser, namedWriteableRegistry, sizeConsumer);
}

searchRequest.source().size(restRequest.paramAsInt("scroll_size", searchRequest.source().size()));
Expand Down Expand Up @@ -87,4 +93,9 @@ private XContentParser extractRequestSpecificFields(RestRequest restRequest,
private static void failOnSizeSpecified() {
throw new IllegalArgumentException("invalid parameter [size], use [max_docs] instead");
}

private void setMaxDocsFromSearchSize(Request request, int size) {
LoggingDeprecationHandler.INSTANCE.logRenamedField(null, null, "size", "max_docs", true);
setMaxDocsValidateIdentical(request, size);
}
}