Skip to content

Commit

Permalink
[REST Compatible API] Reindex size field
Browse files Browse the repository at this point in the history
The commit elastic#43373 has removed outer level size field in version 7.
This commit allows for the use of the size field in server ES8 using
compatible REST API.

relates elastic#51816
  • Loading branch information
pgomulka committed Feb 16, 2021
1 parent f09a2b9 commit c39de97
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.fasterxml.jackson.databind.node.TextNode;
import org.elasticsearch.gradle.test.rest.transform.RestTestTransformGlobalSetup;
import org.elasticsearch.gradle.test.rest.transform.RestTestTransformGlobalTeardown;
import org.gradle.api.tasks.Internal;

import javax.annotation.Nullable;
import java.util.Iterator;
Expand Down Expand Up @@ -73,6 +74,7 @@ public ObjectNode transformTeardown(@Nullable ObjectNode teardownNodeParent) {
* features: allowed_warnings
* </pre>
*/
@Internal
public abstract String getSkipFeatureName();

private boolean hasFeature(ArrayNode skipParent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.gradle.test.rest.transform.RestTestTransformByParentObject;
import org.elasticsearch.gradle.test.rest.transform.feature.FeatureInjector;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;

import java.util.Map;

Expand Down Expand Up @@ -49,6 +50,7 @@ public void transformTest(ObjectNode doNodeParent) {
}

@Override
@Internal
public String getKeyToFind() {
return "do";
}
Expand Down
17 changes: 17 additions & 0 deletions modules/reindex/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ apply plugin: 'elasticsearch.test-with-dependencies'
apply plugin: 'elasticsearch.jdk-download'
apply plugin: 'elasticsearch.yaml-rest-test'
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'
apply plugin: 'elasticsearch.internal-cluster-test'

esplugin {
Expand Down Expand Up @@ -158,3 +159,19 @@ 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',
'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 @@ -15,6 +15,7 @@
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.compatibility.RestApiCompatibleVersion;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lucene.uid.Versions;
Expand Down Expand Up @@ -346,9 +347,16 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

PARSER.declareField(sourceParser::parse, new ParseField("source"), ObjectParser.ValueType.OBJECT);
PARSER.declareField((p, v, c) -> destParser.parse(p, v.getDestination(), c), new ParseField("dest"), ObjectParser.ValueType.OBJECT);
PARSER.declareInt(ReindexRequest::setMaxDocsValidateIdentical, new ParseField("max_docs"));

PARSER.declareInt(ReindexRequest::setMaxDocsValidateIdentical,
new ParseField("max_docs", "size").withRestApiCompatibilityVersions(RestApiCompatibleVersion.V_7));

PARSER.declareInt(ReindexRequest::setMaxDocsValidateIdentical,
new ParseField("max_docs").withRestApiCompatibilityVersions(RestApiCompatibleVersion.V_8));
// avoid silently accepting an ignored size.
PARSER.declareInt((r,s) -> failOnSizeSpecified(), new ParseField("size"));
PARSER.declareInt((r,s) -> failOnSizeSpecified(),
new ParseField("size").withRestApiCompatibilityVersions(RestApiCompatibleVersion.V_8));

PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p)), new ParseField("script"),
ObjectParser.ValueType.OBJECT);
PARSER.declareString(ReindexRequest::setConflicts, new ParseField("conflicts"));
Expand Down

0 comments on commit c39de97

Please sign in to comment.