Skip to content
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

Deprecate types in update_by_query and delete_by_query #36365

2 changes: 1 addition & 1 deletion docs/java-api/docs/update-by-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ This API doesn't allow you to move the documents it touches, just modify their
source. This is intentional! We've made no provisions for removing the document
from its original location.

You can also perform these operations on multiple indices and types at once, similar to the search API:
You can also perform these operations on multiple indices at once, similar to the search API:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void testUpdateByQuery() {
// tag::update-by-query-multi-index
UpdateByQueryRequestBuilder updateByQuery =
new UpdateByQueryRequestBuilder(client, UpdateByQueryAction.INSTANCE);
updateByQuery.source("foo", "bar").source().setTypes("a", "b");
updateByQuery.source("foo", "bar");
BulkByScrollResponse response = updateByQuery.get();
// end::update-by-query-multi-index
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,43 @@

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.test.rest.FakeRestRequest;
import org.elasticsearch.test.rest.RestActionTestCase;

import org.junit.Before;
import java.io.IOException;

import static java.util.Collections.emptyList;
import static org.mockito.Mockito.mock;

public class RestDeleteByQueryActionTests extends ESTestCase {
public class RestDeleteByQueryActionTests extends RestActionTestCase {
private RestDeleteByQueryAction action;

@Before
public void setUpAction() {
action = new RestDeleteByQueryAction(Settings.EMPTY, controller());
}

public void testTypeInPath() throws IOException {
RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
.withMethod(RestRequest.Method.POST)
.withPath("/some_index/some_type/_delete_by_query")
.build();
dispatchRequest(request);

// checks the type in the URL is propagated correctly to the request object
// only works after the request is dispatched, so its params are filled from url.
DeleteByQueryRequest dbqRequest = action.buildRequest(request);
assertArrayEquals(new String[]{"some_type"}, dbqRequest.getDocTypes());

// RestDeleteByQueryAction itself doesn't check for a deprecated type usage
// checking here for a deprecation from its internal search request
assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE);
}

public void testParseEmpty() throws IOException {
RestDeleteByQueryAction action = new RestDeleteByQueryAction(Settings.EMPTY, mock(RestController.class));
DeleteByQueryRequest request = action.buildRequest(new FakeRestRequest.Builder(new NamedXContentRegistry(emptyList()))
.build());
DeleteByQueryRequest request = action.buildRequest(new FakeRestRequest.Builder(new NamedXContentRegistry(emptyList())).build());
assertEquals(AbstractBulkByScrollRequest.SIZE_ALL_MATCHES, request.getSize());
assertEquals(AbstractBulkByScrollRequest.DEFAULT_SCROLL_SIZE, request.getSearchRequest().source().size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,44 @@

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.test.rest.FakeRestRequest;
import org.elasticsearch.test.rest.RestActionTestCase;

import org.junit.Before;
import java.io.IOException;

import static java.util.Collections.emptyList;
import static org.mockito.Mockito.mock;

public class RestUpdateByQueryActionTests extends ESTestCase {
public class RestUpdateByQueryActionTests extends RestActionTestCase {

private RestUpdateByQueryAction action;

@Before
public void setUpAction() {
action = new RestUpdateByQueryAction(Settings.EMPTY, controller());
}

public void testTypeInPath() throws IOException {
RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
.withMethod(RestRequest.Method.POST)
.withPath("/some_index/some_type/_update_by_query")
.build();
dispatchRequest(request);

// checks the type in the URL is propagated correctly to the request object
// only works after the request is dispatched, so its params are filled from url.
UpdateByQueryRequest ubqRequest = action.buildRequest(request);
assertArrayEquals(new String[]{"some_type"}, ubqRequest.getDocTypes());

// RestUpdateByQueryAction itself doesn't check for a deprecated type usage
// checking here for a deprecation from its internal search request
assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE);
}

public void testParseEmpty() throws IOException {
RestUpdateByQueryAction action = new RestUpdateByQueryAction(Settings.EMPTY, mock(RestController.class));
UpdateByQueryRequest request = action.buildRequest(new FakeRestRequest.Builder(new NamedXContentRegistry(emptyList()))
.build());
UpdateByQueryRequest request = action.buildRequest(new FakeRestRequest.Builder(new NamedXContentRegistry(emptyList())).build());
assertEquals(AbstractBulkByScrollRequest.SIZE_ALL_MATCHES, request.getSize());
assertEquals(AbstractBulkByScrollRequest.DEFAULT_SCROLL_SIZE, request.getSearchRequest().source().size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- do:
index:
index: test
type: foo
type: _doc
id: 1
body: { "text": "test" }
- do:
Expand Down Expand Up @@ -42,7 +42,7 @@
- do:
index:
index: test
type: foo
type: _doc
id: 1
body: { "text": "test" }
- do:
Expand Down Expand Up @@ -99,7 +99,7 @@
- do:
index:
index: test
type: foo
type: _doc
id: 1
body: { "text": "test" }
- do:
Expand All @@ -108,7 +108,7 @@
- do:
index:
index: test
type: foo
type: _doc
id: 1
body: { "text": "test2" }

Expand All @@ -124,12 +124,12 @@
- match: {version_conflicts: 1}
- match: {batches: 1}
- match: {failures.0.index: test}
- match: {failures.0.type: foo}
- match: {failures.0.type: _doc}
- match: {failures.0.id: "1"}
- match: {failures.0.status: 409}
- match: {failures.0.cause.type: version_conflict_engine_exception}
# Use a regex so we don't mind if the current version isn't always 1. Sometimes it comes out 2.
- match: {failures.0.cause.reason: "/\\[foo\\]\\[1\\]:.version.conflict,.current.version.\\[\\d+\\].is.different.than.the.one.provided.\\[\\d+\\]/"}
- match: {failures.0.cause.reason: "/\\[_doc\\]\\[1\\]:.version.conflict,.current.version.\\[\\d+\\].is.different.than.the.one.provided.\\[\\d+\\]/"}
- match: {failures.0.cause.shard: /\d+/}
- match: {failures.0.cause.index: test}
- gte: { took: 0 }
Expand All @@ -154,7 +154,7 @@
- do:
index:
index: test
type: foo
type: _doc
id: 1
body: { "text": "test" }
- do:
Expand All @@ -163,7 +163,7 @@
- do:
index:
index: test
type: foo
type: _doc
id: 1
body: { "text": "test2" }

Expand Down Expand Up @@ -197,13 +197,13 @@
- do:
index:
index: twitter
type: tweet
type: _doc
id: 1
body: { "user": "kimchy" }
- do:
index:
index: twitter
type: tweet
type: _doc
id: 2
body: { "user": "junk" }
- do:
Expand Down Expand Up @@ -234,13 +234,13 @@
- do:
index:
index: twitter
type: tweet
type: _doc
id: 1
body: { "user": "kimchy" }
- do:
index:
index: twitter
type: tweet
type: _doc
id: 2
body: { "user": "kimchy" }
- do:
Expand Down Expand Up @@ -281,17 +281,17 @@
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
indices.refresh: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- do:
index:
index: test
type: test
type: _doc
id: 1
body: { "text": "test" }
- do:
Expand All @@ -36,7 +36,7 @@
- do:
index:
index: test
type: test
type: _doc
id: 1
body: { "text": "test" }
- do:
Expand All @@ -53,7 +53,7 @@
- do:
index:
index: test
type: test
type: _doc
id: 1
body: { "text": "test" }
- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- do:
index:
index: index1
type: type1
type: _doc
id: 1
version: 0 # Starting version is zero
version_type: external
Expand All @@ -24,6 +24,6 @@
- do:
get:
index: index1
type: type1
type: _doc
id: 1
- match: {_version: 0}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- do:
index:
index: test
type: test
type: _doc
id: 1
body: {"text": "test"}
- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
indices.refresh: {}
Expand Down Expand Up @@ -50,17 +50,17 @@
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
indices.refresh: {}
Expand Down Expand Up @@ -91,17 +91,17 @@
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
indices.refresh: {}
Expand Down Expand Up @@ -151,17 +151,17 @@
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
index:
index: test
type: foo
type: _doc
body: { "text": "test" }
- do:
indices.refresh: {}
Expand Down
Loading