diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequest.java index 8dc747474c4..4464543a629 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequest.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.admin.cluster.shards; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.support.IndicesOptions; @@ -29,14 +30,15 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; +import java.util.Objects; public class ClusterSearchShardsRequest extends MasterNodeReadRequest implements IndicesRequest.Replaceable { - private String[] indices; + public static final Version V_5_1_0_UNRELEASED = Version.fromId(5010099); + private String[] indices = Strings.EMPTY_ARRAY; @Nullable private String routing; @Nullable private String preference; - private String[] types = Strings.EMPTY_ARRAY; private IndicesOptions indicesOptions = IndicesOptions.lenientExpandOpen(); @@ -57,14 +59,9 @@ public class ClusterSearchShardsRequest extends MasterNodeReadRequest client.admin().cluster().searchShards(clusterSearchShardsRequest, new RestToXContentListener<>(channel)); } } diff --git a/core/src/test/java/org/elasticsearch/VersionTests.java b/core/src/test/java/org/elasticsearch/VersionTests.java index fb21942212c..6ffa9f0a390 100644 --- a/core/src/test/java/org/elasticsearch/VersionTests.java +++ b/core/src/test/java/org/elasticsearch/VersionTests.java @@ -19,6 +19,7 @@ package org.elasticsearch; +import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.Settings; @@ -289,6 +290,7 @@ public class VersionTests extends ESTestCase { // once we released 5.0.0 and it's added to Version.java we need to remove this constant assertUnknownVersion(Script.V_5_1_0_UNRELEASED); // once we released 5.0.0 and it's added to Version.java we need to remove this constant + assertUnknownVersion(ClusterSearchShardsRequest.V_5_1_0_UNRELEASED); } public static void assertUnknownVersion(Version version) { diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequestTests.java new file mode 100644 index 00000000000..7c38a7ff656 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequestTests.java @@ -0,0 +1,80 @@ +/* + * 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.action.admin.cluster.shards; + +import org.elasticsearch.Version; +import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.common.io.stream.BytesStreamOutput; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.VersionUtils; + +public class ClusterSearchShardsRequestTests extends ESTestCase { + + public void testSerialization() throws Exception { + ClusterSearchShardsRequest request = new ClusterSearchShardsRequest(); + if (randomBoolean()) { + int numIndices = randomIntBetween(1, 5); + String[] indices = new String[numIndices]; + for (int i = 0; i < numIndices; i++) { + indices[i] = randomAsciiOfLengthBetween(3, 10); + } + request.indices(indices); + } + if (randomBoolean()) { + request.indicesOptions( + IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean())); + } + if (randomBoolean()) { + request.preference(randomAsciiOfLengthBetween(3, 10)); + } + if (randomBoolean()) { + int numRoutings = randomIntBetween(1, 3); + String[] routings = new String[numRoutings]; + for (int i = 0; i < numRoutings; i++) { + routings[i] = randomAsciiOfLengthBetween(3, 10); + } + request.routing(routings); + } + + Version version = VersionUtils.randomVersion(random()); + try (BytesStreamOutput out = new BytesStreamOutput()) { + out.setVersion(version); + request.writeTo(out); + try (StreamInput in = out.bytes().streamInput()) { + in.setVersion(version); + ClusterSearchShardsRequest deserialized = new ClusterSearchShardsRequest(); + deserialized.readFrom(in); + assertArrayEquals(request.indices(), deserialized.indices()); + assertSame(request.indicesOptions(), deserialized.indicesOptions()); + assertEquals(request.routing(), deserialized.routing()); + assertEquals(request.preference(), deserialized.preference()); + } + } + } + + public void testIndicesMustNotBeNull() { + ClusterSearchShardsRequest request = new ClusterSearchShardsRequest(); + assertNotNull(request.indices()); + expectThrows(NullPointerException.class, () -> request.indices((String[])null)); + expectThrows(NullPointerException.class, () -> request.indices((String)null)); + expectThrows(NullPointerException.class, () -> request.indices(new String[]{"index1", null, "index3"})); + } +} diff --git a/docs/reference/migration/migrate_6_0/search.asciidoc b/docs/reference/migration/migrate_6_0/search.asciidoc index fe72768e590..cd39141095d 100644 --- a/docs/reference/migration/migrate_6_0/search.asciidoc +++ b/docs/reference/migration/migrate_6_0/search.asciidoc @@ -9,3 +9,9 @@ * Queries on boolean fields now strictly parse boolean-like values. This means only the strings `"true"` and `"false"` will be parsed into their boolean counterparts. Other strings will cause an error to be thrown. + + +==== Search shards API + +The search shards API no longer accepts the `type` url parameter, which didn't +have any effect in previous versions. diff --git a/docs/reference/search/search-shards.asciidoc b/docs/reference/search/search-shards.asciidoc index c07c3755a26..917a50ae9a7 100644 --- a/docs/reference/search/search-shards.asciidoc +++ b/docs/reference/search/search-shards.asciidoc @@ -5,7 +5,7 @@ The search shards api returns the indices and shards that a search request would be executed against. This can give useful feedback for working out issues or planning optimizations with routing and shard preferences. -The `index` and `type` parameters may be single values, or comma-separated. +The `index` may be a single value, or comma-separated. [float] === Usage diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/search_shards.json b/rest-api-spec/src/main/resources/rest-api-spec/api/search_shards.json index e03ed8fef2f..b3de107b797 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/search_shards.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/search_shards.json @@ -3,16 +3,12 @@ "documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html", "methods": ["GET", "POST"], "url": { - "path": "/{index}/{type}/_search_shards", - "paths": ["/_search_shards", "/{index}/_search_shards", "/{index}/{type}/_search_shards"], + "path": "/{index}/_search_shards", + "paths": ["/_search_shards", "/{index}/_search_shards"], "parts": { "index": { "type" : "list", "description" : "A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices" - }, - "type": { - "type" : "list", - "description" : "A comma-separated list of document types to search; leave empty to perform the operation on all types" } }, "params": {