diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/CountRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/CountRequest.java index 6d4589c7861..4b40fde53e9 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/CountRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/CountRequest.java @@ -90,7 +90,8 @@ public final class CountRequest extends ActionRequest implements IndicesRequest. /** * The document types to execute the count against. Defaults to be executed against all types. * - * @deprecated Types are going away, prefer filtering on a type. + * @deprecated Types are in the process of being removed. Instead of using a type, prefer to + * filter on a field on the document. */ @Deprecated public CountRequest types(String... types) { @@ -172,6 +173,11 @@ public final class CountRequest extends ActionRequest implements IndicesRequest. return this; } + /** + * @deprecated Types are in the process of being removed. Instead of using a type, prefer to + * filter on a field on the document. + */ + @Deprecated public String[] types() { return Arrays.copyOf(this.types, this.types.length); } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java index 831c39ed28b..766385c99aa 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java @@ -174,8 +174,8 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { sourceBuilder.fetchSource(false); // end::search-source-filtering-off // tag::search-source-filtering-includes - String[] includeFields = new String[] {"title", "user", "innerObject.*"}; - String[] excludeFields = new String[] {"_type"}; + String[] includeFields = new String[] {"title", "innerObject.*"}; + String[] excludeFields = new String[] {"user"}; sourceBuilder.fetchSource(includeFields, excludeFields); // end::search-source-filtering-includes sourceBuilder.fetchSource(true); @@ -247,7 +247,6 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { for (SearchHit hit : searchHits) { // tag::search-hits-singleHit-properties String index = hit.getIndex(); - String type = hit.getType(); String id = hit.getId(); float score = hit.getScore(); // end::search-hits-singleHit-properties @@ -263,8 +262,8 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { assertEquals(3, totalHits); assertNotNull(hits.getHits()[0].getSourceAsString()); assertNotNull(hits.getHits()[0].getSourceAsMap().get("title")); - assertNotNull(hits.getHits()[0].getSourceAsMap().get("user")); assertNotNull(hits.getHits()[0].getSourceAsMap().get("innerObject")); + assertNull(hits.getHits()[0].getSourceAsMap().get("user")); } } @@ -1242,18 +1241,6 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { assertTrue(latch.await(30L, TimeUnit.SECONDS)); } - { - // tag::multi-search-request-index - MultiSearchRequest request = new MultiSearchRequest(); - request.add(new SearchRequest("posts") // <1> - .types("doc")); // <2> - // end::multi-search-request-index - MultiSearchResponse response = client.msearch(request, RequestOptions.DEFAULT); - MultiSearchResponse.Item firstResponse = response.getResponses()[0]; - assertNull(firstResponse.getFailure()); - SearchResponse searchResponse = firstResponse.getResponse(); - assertEquals(3, searchResponse.getHits().getTotalHits()); - } } private void indexSearchTestData() throws IOException { @@ -1304,19 +1291,12 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase { // end::count-request-basic } { - // tag::count-request-indices-types - CountRequest countRequest = new CountRequest("blog"); // <1> - countRequest.types("doc"); // <2> - // end::count-request-indices-types - // tag::count-request-routing - countRequest.routing("routing"); // <1> - // end::count-request-routing - // tag::count-request-indicesOptions - countRequest.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> - // end::count-request-indicesOptions - // tag::count-request-preference - countRequest.preference("_local"); // <1> - // end::count-request-preference + // tag::count-request-args + CountRequest countRequest = new CountRequest("blog") // <1> + .routing("routing") // <2> + .indicesOptions(IndicesOptions.lenientExpandOpen()) // <3> + .preference("_local"); // <4> + // end::count-request-args assertNotNull(client.count(countRequest, RequestOptions.DEFAULT)); } { diff --git a/docs/java-rest/high-level/search/count.asciidoc b/docs/java-rest/high-level/search/count.asciidoc index f70e1e1fd4d..2796d34ab36 100644 --- a/docs/java-rest/high-level/search/count.asciidoc +++ b/docs/java-rest/high-level/search/count.asciidoc @@ -29,34 +29,16 @@ include-tagged::{doc-tests-file}[{api}-request-basic] [[java-rest-high-count-request-optional]] ===== Count Request optional arguments -Let's first look at some of the optional arguments of a +{request}+: +A +{request}+ also takes the following optional arguments: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indices-types] +include-tagged::{doc-tests-file}[{api}-request-args] -------------------------------------------------- <1> Restricts the request to an index -<2> Limits the request to a type - -There are a couple of other interesting optional parameters: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-routing] --------------------------------------------------- -<1> Set a routing parameter - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-indicesOptions] --------------------------------------------------- -<1> Setting `IndicesOptions` controls how unavailable indices are resolved and how wildcard expressions are expanded - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request-preference] --------------------------------------------------- -<1> Use the preference parameter e.g. to execute the search to prefer local shards. The default is to randomize across shards. +<2> Set a routing parameter +<3> Setting `IndicesOptions` controls how unavailable indices are resolved and how wildcard expressions are expanded +<4> Use the preference parameter e.g. to execute the search to prefer local shards. The default is to randomize across shards. ===== Using the SearchSourceBuilder in CountRequest diff --git a/docs/java-rest/high-level/search/search.asciidoc b/docs/java-rest/high-level/search/search.asciidoc index 81e680b9250..ab27a432fe5 100644 --- a/docs/java-rest/high-level/search/search.asciidoc +++ b/docs/java-rest/high-level/search/search.asciidoc @@ -289,8 +289,8 @@ be iterated over: include-tagged::{doc-tests-file}[{api}-hits-singleHit] -------------------------------------------------- -The `SearchHit` provides access to basic information like index, type, docId and -score of each search hit: +The `SearchHit` provides access to basic information like index, document ID +and score of each search hit: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- diff --git a/docs/reference/search/count.asciidoc b/docs/reference/search/count.asciidoc index 3b32222786f..19ba77cd129 100644 --- a/docs/reference/search/count.asciidoc +++ b/docs/reference/search/count.asciidoc @@ -14,9 +14,9 @@ PUT /twitter/_doc/1?refresh "user": "kimchy" } -GET /twitter/_doc/_count?q=user:kimchy +GET /twitter/_count?q=user:kimchy -GET /twitter/_doc/_count +GET /twitter/_count { "query" : { "term" : { "user" : "kimchy" } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/count/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/count/10_basic.yml index 32256811e0f..a8ef8c01e51 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/count/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/count/10_basic.yml @@ -18,7 +18,6 @@ setup: - do: count: index: test - type: test body: query: match: @@ -29,7 +28,6 @@ setup: - do: count: index: test - type: test body: query: match: @@ -43,7 +41,6 @@ setup: - do: count: index: test - type: test body: { } - match: {count : 1} @@ -51,7 +48,6 @@ setup: - do: count: index: test - type: test - match: {count : 1} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/count/11_basic_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/count/11_basic_with_types.yml new file mode 100644 index 00000000000..48cfc610b43 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/count/11_basic_with_types.yml @@ -0,0 +1,66 @@ +setup: + - do: + indices.create: + index: test + - do: + index: + index: test + type: test + id: 1 + body: { foo: bar } + + - do: + indices.refresh: + index: [test] + +--- +"count with body": + - do: + count: + index: test + type: test + body: + query: + match: + foo: bar + + - match: {count : 1} + + - do: + count: + index: test + body: + query: + match: + foo: test + + - match: {count : 0} + +--- +"count with empty body": +# empty body should default to match_all query + - do: + count: + index: test + type: test + body: { } + + - match: {count : 1} + + - do: + count: + index: test + type: test + + - match: {count : 1} + +--- +"count body without query element": + - do: + catch: bad_request + count: + index: test + type: test + body: + match: + foo: bar diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yml index a14423cef11..c16844478f1 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yml @@ -50,7 +50,7 @@ setup: - index: index_3 - query: match_all: {} - - type: test + - {} - query: match_all: {} @@ -82,7 +82,7 @@ setup: - index: index_3 - query: match_all: {} - - type: test + - {} - query: match_all: {} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/12_basic_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/12_basic_with_types.yml new file mode 100644 index 00000000000..a14423cef11 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/12_basic_with_types.yml @@ -0,0 +1,95 @@ +--- +setup: + + - do: + index: + index: index_1 + type: test + id: 1 + body: { foo: bar } + + - do: + index: + index: index_1 + type: test + id: 2 + body: { foo: baz } + + - do: + index: + index: index_1 + type: test + id: 3 + body: { foo: foo } + + - do: + index: + index: index_2 + type: test + id: 1 + body: { foo: foo } + + - do: + indices.refresh: {} + +--- +"Basic multi-search": + + - do: + msearch: + body: + - index: index_* + - query: + match: {foo: foo} + - index: index_2 + - query: + match_all: {} + - index: index_1 + - query: + match: {foo: foo} + - index: index_3 + - query: + match_all: {} + - type: test + - query: + match_all: {} + + - match: { responses.0.hits.total: 2 } + - match: { responses.1.hits.total: 1 } + - match: { responses.2.hits.total: 1 } + - match: { responses.3.error.root_cause.0.type: index_not_found_exception } + - match: { responses.3.error.root_cause.0.reason: "/no.such.index/" } + - match: { responses.3.error.root_cause.0.index: index_3 } + - match: { responses.4.hits.total: 4 } + +--- +"Least impact smoke test": +# only passing these parameters to make sure they are consumed + - do: + msearch: + max_concurrent_shard_requests: 1 + max_concurrent_searches: 1 + body: + - index: index_* + - query: + match: {foo: foo} + - index: index_2 + - query: + match_all: {} + - index: index_1 + - query: + match: {foo: foo} + - index: index_3 + - query: + match_all: {} + - type: test + - query: + match_all: {} + + - match: { responses.0.hits.total: 2 } + - match: { responses.1.hits.total: 1 } + - match: { responses.2.hits.total: 1 } + - match: { responses.3.error.root_cause.0.type: index_not_found_exception } + - match: { responses.3.error.root_cause.0.reason: "/no.such.index/" } + - match: { responses.3.error.root_cause.0.index: index_3 } + - match: { responses.4.hits.total: 4 } diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index 4e589f613a6..71eddc65c18 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -310,6 +310,7 @@ import org.elasticsearch.rest.action.ingest.RestGetPipelineAction; import org.elasticsearch.rest.action.ingest.RestPutPipelineAction; import org.elasticsearch.rest.action.ingest.RestSimulatePipelineAction; import org.elasticsearch.rest.action.search.RestClearScrollAction; +import org.elasticsearch.rest.action.search.RestCountAction; import org.elasticsearch.rest.action.search.RestExplainAction; import org.elasticsearch.rest.action.search.RestMultiSearchAction; import org.elasticsearch.rest.action.search.RestSearchAction; @@ -595,7 +596,7 @@ public class ActionModule extends AbstractModule { registerHandler.accept(new RestGetSourceAction(settings, restController)); registerHandler.accept(new RestMultiGetAction(settings, restController)); registerHandler.accept(new RestDeleteAction(settings, restController)); - registerHandler.accept(new org.elasticsearch.rest.action.document.RestCountAction(settings, restController)); + registerHandler.accept(new RestCountAction(settings, restController)); registerHandler.accept(new RestTermVectorsAction(settings, restController)); registerHandler.accept(new RestMultiTermVectorsAction(settings, restController)); registerHandler.accept(new RestBulkAction(settings, restController)); diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchRequest.java b/server/src/main/java/org/elasticsearch/action/search/SearchRequest.java index f4b501b7697..d5ab34fe582 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchRequest.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchRequest.java @@ -217,7 +217,11 @@ public final class SearchRequest extends ActionRequest implements IndicesRequest /** * The document types to execute the search against. Defaults to be executed against * all types. + * + * @deprecated Types are in the process of being removed. Instead of using a type, prefer to + * filter on a field on the document. */ + @Deprecated public String[] types() { return types; } @@ -225,7 +229,9 @@ public final class SearchRequest extends ActionRequest implements IndicesRequest /** * The document types to execute the search against. Defaults to be executed against * all types. - * @deprecated Types are going away, prefer filtering on a type. + * + * @deprecated Types are in the process of being removed. Instead of using a type, prefer to + * filter on a field on the document. */ @Deprecated public SearchRequest types(String... types) { diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestCountAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java similarity index 88% rename from server/src/main/java/org/elasticsearch/rest/action/document/RestCountAction.java rename to server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java index a66b17cc5a5..99ea1c81fa9 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestCountAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java @@ -17,13 +17,15 @@ * under the License. */ -package org.elasticsearch.rest.action.document; +package org.elasticsearch.rest.action.search; +import org.apache.logging.log4j.LogManager; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.query.QueryBuilder; @@ -44,6 +46,11 @@ import static org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHead import static org.elasticsearch.search.internal.SearchContext.DEFAULT_TERMINATE_AFTER; public class RestCountAction extends BaseRestHandler { + private static final DeprecationLogger deprecationLogger = new DeprecationLogger( + LogManager.getLogger(RestCountAction.class)); + static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" + + " Specifying types in count requests is deprecated."; + public RestCountAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(POST, "/_count", this); @@ -80,7 +87,12 @@ public class RestCountAction extends BaseRestHandler { if (minScore != -1f) { searchSourceBuilder.minScore(minScore); } - countRequest.types(Strings.splitStringByCommaToArray(request.param("type"))); + + if (request.hasParam("type")) { + deprecationLogger.deprecated(TYPES_DEPRECATION_MESSAGE); + countRequest.types(Strings.splitStringByCommaToArray(request.param("type"))); + } + countRequest.preference(request.param("preference")); final int terminateAfter = request.paramAsInt("terminate_after", DEFAULT_TERMINATE_AFTER); diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java index 6239015dae4..d3a45fa727b 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java @@ -19,6 +19,7 @@ package org.elasticsearch.rest.action.search; +import org.apache.logging.log4j.LogManager; import org.elasticsearch.action.search.MultiSearchRequest; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.support.IndicesOptions; @@ -27,6 +28,7 @@ import org.elasticsearch.common.CheckedBiConsumer; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContentParser; @@ -46,9 +48,13 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestMultiSearchAction extends BaseRestHandler { - private static final Set RESPONSE_PARAMS = Collections.singleton(RestSearchAction.TYPED_KEYS_PARAM); + private static final DeprecationLogger deprecationLogger = new DeprecationLogger( + LogManager.getLogger(RestMultiSearchAction.class)); + static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" + + " Specifying types in multi search requests is deprecated."; + private final boolean allowExplicitIndex; public RestMultiSearchAction(Settings settings, RestController controller) { @@ -96,6 +102,9 @@ public class RestMultiSearchAction extends BaseRestHandler { } parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex, (searchRequest, parser) -> { + if (searchRequest.types().length > 0) { + deprecationLogger.deprecated(TYPES_DEPRECATION_MESSAGE); + } searchRequest.source(SearchSourceBuilder.fromXContent(parser, false)); multiRequest.add(searchRequest); }); diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 0a0bf1b6e38..60fd77e46aa 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -54,10 +54,12 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.search.suggest.SuggestBuilders.termSuggestion; public class RestSearchAction extends BaseRestHandler { - public static final String TYPED_KEYS_PARAM = "typed_keys"; private static final Set RESPONSE_PARAMS = Collections.singleton(TYPED_KEYS_PARAM); + private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSearchAction.class)); + static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" + + " Specifying types in search requests is deprecated."; public RestSearchAction(Settings settings, RestController controller) { super(settings); @@ -150,11 +152,10 @@ public class RestSearchAction extends BaseRestHandler { searchRequest.scroll(new Scroll(parseTimeValue(scroll, null, "scroll"))); } - String types = request.param("type"); - if (types != null) { - deprecationLogger.deprecated("The {index}/{type}/_search endpoint is deprecated, use {index}/_search instead"); + if (request.hasParam("type")) { + deprecationLogger.deprecated(TYPES_DEPRECATION_MESSAGE); + searchRequest.types(Strings.splitStringByCommaToArray(request.param("type"))); } - searchRequest.types(Strings.splitStringByCommaToArray(types)); searchRequest.routing(request.param("routing")); searchRequest.preference(request.param("preference")); searchRequest.indicesOptions(IndicesOptions.fromRequest(request, searchRequest.indicesOptions())); diff --git a/server/src/main/java/org/elasticsearch/search/SearchHit.java b/server/src/main/java/org/elasticsearch/search/SearchHit.java index 7eb1139705d..4532385f313 100644 --- a/server/src/main/java/org/elasticsearch/search/SearchHit.java +++ b/server/src/main/java/org/elasticsearch/search/SearchHit.java @@ -183,7 +183,11 @@ public final class SearchHit implements Streamable, ToXContentObject, Iterable { + searchRequest.source(SearchSourceBuilder.fromXContent(parser, false)); + request.add(searchRequest); + }); + return request; } @Override diff --git a/server/src/test/java/org/elasticsearch/rest/action/search/RestCountActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/search/RestCountActionTests.java new file mode 100644 index 00000000000..a6404332772 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/rest/action/search/RestCountActionTests.java @@ -0,0 +1,82 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.rest.action.search; + +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; +import org.elasticsearch.rest.RestChannel; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequest.Method; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.rest.FakeRestChannel; +import org.elasticsearch.test.rest.FakeRestRequest; +import org.elasticsearch.usage.UsageService; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.mockito.Mockito.mock; + +public class RestCountActionTests extends ESTestCase { + private RestController controller; + + public void setUp() throws Exception { + super.setUp(); + controller = new RestController(Collections.emptySet(), null, + mock(NodeClient.class), + new NoneCircuitBreakerService(), + new UsageService()); + new RestCountAction(Settings.EMPTY, controller); + } + + public void testTypeInPath() { + RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(Method.POST) + .withPath("/some_index/some_type/_count") + .build(); + + performRequest(request); + assertWarnings(RestCountAction.TYPES_DEPRECATION_MESSAGE); + } + + public void testTypeParameter() { + Map params = new HashMap<>(); + params.put("type", "some_type"); + + RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(Method.GET) + .withPath("/some_index/_count") + .withParams(params) + .build(); + + performRequest(request); + assertWarnings(RestCountAction.TYPES_DEPRECATION_MESSAGE); + } + + private void performRequest(RestRequest request) { + RestChannel channel = new FakeRestChannel(request, false, 1); + ThreadContext threadContext = new ThreadContext(Settings.EMPTY); + controller.dispatchRequest(request, channel, threadContext); + } +} diff --git a/server/src/test/java/org/elasticsearch/rest/action/search/RestMultiSearchActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/search/RestMultiSearchActionTests.java new file mode 100644 index 00000000000..7469758273b --- /dev/null +++ b/server/src/test/java/org/elasticsearch/rest/action/search/RestMultiSearchActionTests.java @@ -0,0 +1,86 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.rest.action.search; + +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; +import org.elasticsearch.rest.RestChannel; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.rest.FakeRestChannel; +import org.elasticsearch.test.rest.FakeRestRequest; +import org.elasticsearch.usage.UsageService; + +import java.nio.charset.StandardCharsets; +import java.util.Collections; + +import static org.mockito.Mockito.mock; + +public class RestMultiSearchActionTests extends ESTestCase { + private RestController controller; + + public void setUp() throws Exception { + super.setUp(); + controller = new RestController(Collections.emptySet(), null, + mock(NodeClient.class), + new NoneCircuitBreakerService(), + new UsageService()); + new RestMultiSearchAction(Settings.EMPTY, controller); + } + + public void testTypeInPath() { + String content = "{ \"index\": \"some_index\" } \n {} \n"; + BytesArray bytesContent = new BytesArray(content.getBytes(StandardCharsets.UTF_8)); + + RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.GET) + .withPath("/some_index/some_type/_msearch") + .withContent(bytesContent, XContentType.JSON) + .build(); + + performRequest(request); + assertWarnings(RestMultiSearchAction.TYPES_DEPRECATION_MESSAGE); + } + + public void testTypeInBody() { + String content = "{ \"index\": \"some_index\", \"type\": \"some_type\" } \n {} \n"; + BytesArray bytesContent = new BytesArray(content.getBytes(StandardCharsets.UTF_8)); + + RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.POST) + .withPath("/some_index/_msearch") + .withContent(bytesContent, XContentType.JSON) + .build(); + + performRequest(request); + assertWarnings(RestMultiSearchAction.TYPES_DEPRECATION_MESSAGE); + } + + private void performRequest(RestRequest request) { + RestChannel channel = new FakeRestChannel(request, false, 1); + ThreadContext threadContext = new ThreadContext(Settings.EMPTY); + controller.dispatchRequest(request, channel, threadContext); + } +} diff --git a/server/src/test/java/org/elasticsearch/rest/action/search/RestSearchActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/search/RestSearchActionTests.java new file mode 100644 index 00000000000..e738fa5c9dc --- /dev/null +++ b/server/src/test/java/org/elasticsearch/rest/action/search/RestSearchActionTests.java @@ -0,0 +1,81 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.rest.action.search; + +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; +import org.elasticsearch.rest.RestChannel; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.rest.FakeRestChannel; +import org.elasticsearch.test.rest.FakeRestRequest; +import org.elasticsearch.usage.UsageService; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.mockito.Mockito.mock; + +public class RestSearchActionTests extends ESTestCase { + private RestController controller; + + public void setUp() throws Exception { + super.setUp(); + controller = new RestController(Collections.emptySet(), null, + mock(NodeClient.class), + new NoneCircuitBreakerService(), + new UsageService()); + new RestSearchAction(Settings.EMPTY, controller); + } + + public void testTypeInPath() { + RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.GET) + .withPath("/some_index/some_type/_search") + .build(); + + performRequest(request); + assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE); + } + + public void testTypeParameter() { + Map params = new HashMap<>(); + params.put("type", "some_type"); + + RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.GET) + .withPath("/some_index/_search") + .withParams(params) + .build(); + + performRequest(request); + assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE); + } + + private void performRequest(RestRequest request) { + RestChannel channel = new FakeRestChannel(request, false, 1); + ThreadContext threadContext = new ThreadContext(Settings.EMPTY); + controller.dispatchRequest(request, channel, threadContext); + } +} diff --git a/server/src/test/resources/org/elasticsearch/action/search/simple-msearch5.json b/server/src/test/resources/org/elasticsearch/action/search/simple-msearch5.json index f2cc4e0e965..ac3fb4b62d6 100644 --- a/server/src/test/resources/org/elasticsearch/action/search/simple-msearch5.json +++ b/server/src/test/resources/org/elasticsearch/action/search/simple-msearch5.json @@ -1,6 +1,6 @@ {"index":["test0", "test1"], "request_cache": true} {"query" : {"match_all" : {}}} -{"index" : "test2,test3", "type" : "type1", "preference": "_local"} +{"index" : "test2,test3", "preference": "_local"} {"query" : {"match_all" : {}}} -{"index" : ["test4", "test1"], "type" : [ "type2", "type1" ], "routing": "123"} +{"index" : ["test4", "test1"], "routing": "123"} {"query" : {"match_all" : {}}} \ No newline at end of file diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexAuditUpgradeIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexAuditUpgradeIT.java index 2a681afc14c..cc704d71d0e 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexAuditUpgradeIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexAuditUpgradeIT.java @@ -49,7 +49,7 @@ public class IndexAuditUpgradeIT extends AbstractUpgradeTestCase { } private void assertAuditDocsExist() throws Exception { - Response response = client().performRequest(new Request("GET", "/.security_audit_log*/doc/_count")); + Response response = client().performRequest(new Request("GET", "/.security_audit_log*/_count")); assertEquals(200, response.getStatusLine().getStatusCode()); Map responseMap = entityAsMap(response); assertNotNull(responseMap.get("count"));