Skip to content

Throw error when create is used with external #37900

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

Closed
wants to merge 3 commits into from
Closed
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 @@ -21,6 +21,7 @@

import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.CompositeIndicesRequest;
import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.common.io.stream.StreamInput;
Expand Down Expand Up @@ -104,7 +105,14 @@ public ActionRequestValidationException validate() {
if (destination.version() != Versions.MATCH_ANY && destination.version() != Versions.MATCH_DELETED) {
e = addValidationError("unsupported version for internal versioning [" + destination.version() + ']', e);
}
} else {
if (destination.opType() == DocWriteRequest.OpType.CREATE) {
e = addValidationError("create operations only support internal versioning. use index instead",
e);
return e;
}
}

if (getRemoteInfo() != null) {
if (getSearchRequest().source().query() != null) {
e = addValidationError("reindex from remote sources should use RemoteInfo's query instead of source's query", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@

import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.search.slice.SliceBuilder;

import static java.util.Collections.emptyMap;
import static org.elasticsearch.common.unit.TimeValue.parseTimeValue;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.hamcrest.CoreMatchers.is;

/**
* Tests some of the validation of {@linkplain ReindexRequest}. See reindex's rest tests for much more.
Expand Down Expand Up @@ -65,6 +67,14 @@ public void testNoSliceBuilderSetWithSlicedRequest() {
assertEquals("Validation Failed: 1: can't specify both manual and automatic slicing at the same time;", e.getMessage());
}

public void testReindexShouldThrowErrorWhenCreateIsUsedWithCreate() {
ReindexRequest reindex = newRequest();
reindex.setDestOpType("create");
reindex.setDestVersionType(VersionType.EXTERNAL);
ActionRequestValidationException e = reindex.validate();
assertThat(e.getMessage(), is("Validation Failed: 1: create operations only support internal versioning. use index instead;"));
}

@Override
protected void extraRandomizationForSlice(ReindexRequest original) {
if (randomBoolean()) {
Expand Down