Skip to content

Commit be2ce09

Browse files
authored
Remove types from ValidateQuery API (#46927)
Type information is no longer useful for validating queries; this commit removes the deprecated typed endpoints for this API. Relates to #41059
1 parent d912637 commit be2ce09

File tree

9 files changed

+23
-117
lines changed

9 files changed

+23
-117
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,7 @@ static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) thro
544544

545545
static Request validateQuery(ValidateQueryRequest validateQueryRequest) throws IOException {
546546
String[] indices = validateQueryRequest.indices() == null ? Strings.EMPTY_ARRAY : validateQueryRequest.indices();
547-
String[] types = validateQueryRequest.types() == null || indices.length <= 0 ? Strings.EMPTY_ARRAY : validateQueryRequest.types();
548-
String endpoint = RequestConverters.endpoint(indices, types, "_validate/query");
547+
String endpoint = RequestConverters.endpoint(indices, "_validate/query");
549548
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
550549
RequestConverters.Params params = new RequestConverters.Params();
551550
params.withIndicesOptions(validateQueryRequest.indicesOptions());

client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,15 +1125,13 @@ public void testPutTemplateRequest() throws Exception {
11251125
}
11261126
public void testValidateQuery() throws Exception {
11271127
String[] indices = ESTestCase.randomBoolean() ? null : RequestConvertersTests.randomIndicesNames(0, 5);
1128-
String[] types = ESTestCase.randomBoolean() ? ESTestCase.generateRandomStringArray(5, 5, false, false) : null;
11291128
ValidateQueryRequest validateQueryRequest;
11301129
if (ESTestCase.randomBoolean()) {
11311130
validateQueryRequest = new ValidateQueryRequest(indices);
11321131
} else {
11331132
validateQueryRequest = new ValidateQueryRequest();
11341133
validateQueryRequest.indices(indices);
11351134
}
1136-
validateQueryRequest.types(types);
11371135
Map<String, String> expectedParams = new HashMap<>();
11381136
RequestConvertersTests.setRandomIndicesOptions(validateQueryRequest::indicesOptions, validateQueryRequest::indicesOptions,
11391137
expectedParams);
@@ -1147,9 +1145,6 @@ public void testValidateQuery() throws Exception {
11471145
StringJoiner endpoint = new StringJoiner("/", "/", "");
11481146
if (indices != null && indices.length > 0) {
11491147
endpoint.add(String.join(",", indices));
1150-
if (types != null && types.length > 0) {
1151-
endpoint.add(String.join(",", types));
1152-
}
11531148
}
11541149
endpoint.add("_validate/query");
11551150
Assert.assertThat(request.getEndpoint(), equalTo(endpoint.toString()));

server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ShardValidateQueryRequest.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
package org.elasticsearch.action.admin.indices.validate.query;
2121

22+
import org.elasticsearch.Version;
2223
import org.elasticsearch.action.support.broadcast.BroadcastShardRequest;
23-
import org.elasticsearch.common.Strings;
2424
import org.elasticsearch.common.io.stream.StreamInput;
2525
import org.elasticsearch.common.io.stream.StreamOutput;
2626
import org.elasticsearch.index.query.QueryBuilder;
@@ -36,7 +36,6 @@
3636
public class ShardValidateQueryRequest extends BroadcastShardRequest {
3737

3838
private QueryBuilder query;
39-
private String[] types = Strings.EMPTY_ARRAY;
4039
private boolean explain;
4140
private boolean rewrite;
4241
private long nowInMillis;
@@ -45,12 +44,12 @@ public class ShardValidateQueryRequest extends BroadcastShardRequest {
4544
public ShardValidateQueryRequest(StreamInput in) throws IOException {
4645
super(in);
4746
query = in.readNamedWriteable(QueryBuilder.class);
48-
49-
int typesSize = in.readVInt();
50-
if (typesSize > 0) {
51-
types = new String[typesSize];
52-
for (int i = 0; i < typesSize; i++) {
53-
types[i] = in.readString();
47+
if (in.getVersion().before(Version.V_8_0_0)) {
48+
int typesSize = in.readVInt();
49+
if (typesSize > 0) {
50+
for (int i = 0; i < typesSize; i++) {
51+
in.readString();
52+
}
5453
}
5554
}
5655
filteringAliases = new AliasFilter(in);
@@ -62,7 +61,6 @@ public ShardValidateQueryRequest(StreamInput in) throws IOException {
6261
public ShardValidateQueryRequest(ShardId shardId, AliasFilter filteringAliases, ValidateQueryRequest request) {
6362
super(shardId, request);
6463
this.query = request.query();
65-
this.types = request.types();
6664
this.explain = request.explain();
6765
this.rewrite = request.rewrite();
6866
this.filteringAliases = Objects.requireNonNull(filteringAliases, "filteringAliases must not be null");
@@ -73,10 +71,6 @@ public QueryBuilder query() {
7371
return query;
7472
}
7573

76-
public String[] types() {
77-
return this.types;
78-
}
79-
8074
public boolean explain() {
8175
return this.explain;
8276
}
@@ -97,9 +91,8 @@ public long nowInMillis() {
9791
public void writeTo(StreamOutput out) throws IOException {
9892
super.writeTo(out);
9993
out.writeNamedWriteable(query);
100-
out.writeVInt(types.length);
101-
for (String type : types) {
102-
out.writeString(type);
94+
if (out.getVersion().before(Version.V_8_0_0)) {
95+
out.writeVInt(0); // no types to filter
10396
}
10497
filteringAliases.writeTo(out);
10598
out.writeBoolean(explain);

server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequest.java

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.action.admin.indices.validate.query;
2121

22+
import org.elasticsearch.Version;
2223
import org.elasticsearch.action.ActionRequestValidationException;
2324
import org.elasticsearch.action.ValidateActions;
2425
import org.elasticsearch.action.support.IndicesOptions;
@@ -47,8 +48,6 @@ public class ValidateQueryRequest extends BroadcastRequest<ValidateQueryRequest>
4748
private boolean rewrite;
4849
private boolean allShards;
4950

50-
private String[] types = Strings.EMPTY_ARRAY;
51-
5251
long nowInMillis;
5352

5453
public ValidateQueryRequest() {
@@ -58,11 +57,12 @@ public ValidateQueryRequest() {
5857
public ValidateQueryRequest(StreamInput in) throws IOException {
5958
super(in);
6059
query = in.readNamedWriteable(QueryBuilder.class);
61-
int typesSize = in.readVInt();
62-
if (typesSize > 0) {
63-
types = new String[typesSize];
64-
for (int i = 0; i < typesSize; i++) {
65-
types[i] = in.readString();
60+
if (in.getVersion().before(Version.V_8_0_0)) {
61+
int typesSize = in.readVInt();
62+
if (typesSize > 0) {
63+
for (int i = 0; i < typesSize; i++) {
64+
in.readString();
65+
}
6666
}
6767
}
6868
explain = in.readBoolean();
@@ -100,29 +100,6 @@ public ValidateQueryRequest query(QueryBuilder query) {
100100
return this;
101101
}
102102

103-
/**
104-
* The types of documents the query will run against. Defaults to all types.
105-
*
106-
* @deprecated Types are in the process of being removed. Instead of using a type, prefer to
107-
* filter on a field on the document.
108-
*/
109-
@Deprecated
110-
public String[] types() {
111-
return this.types;
112-
}
113-
114-
/**
115-
* The types of documents the query will run against. Defaults to all types.
116-
*
117-
* @deprecated Types are in the process of being removed. Instead of using a type, prefer to
118-
* filter on a field on the document.
119-
*/
120-
@Deprecated
121-
public ValidateQueryRequest types(String... types) {
122-
this.types = types;
123-
return this;
124-
}
125-
126103
/**
127104
* Indicate if detailed information about query is requested
128105
*/
@@ -169,9 +146,8 @@ public boolean allShards() {
169146
public void writeTo(StreamOutput out) throws IOException {
170147
super.writeTo(out);
171148
out.writeNamedWriteable(query);
172-
out.writeVInt(types.length);
173-
for (String type : types) {
174-
out.writeString(type);
149+
if (out.getVersion().before(Version.V_8_0_0)) {
150+
out.writeVInt(0); // no types to filter
175151
}
176152
out.writeBoolean(explain);
177153
out.writeBoolean(rewrite);
@@ -180,7 +156,7 @@ public void writeTo(StreamOutput out) throws IOException {
180156

181157
@Override
182158
public String toString() {
183-
return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types) + ", query[" + query + "], explain:" + explain +
159+
return "[" + Arrays.toString(indices) + "] query[" + query + "], explain:" + explain +
184160
", rewrite:" + rewrite + ", all_shards:" + allShards;
185161
}
186162

server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequestBuilder.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ public ValidateQueryRequestBuilder(ElasticsearchClient client, ValidateQueryActi
3030
super(client, action, new ValidateQueryRequest());
3131
}
3232

33-
/**
34-
* The types of documents the query will run against. Defaults to all types.
35-
*/
36-
public ValidateQueryRequestBuilder setTypes(String... types) {
37-
request.types(types);
38-
return this;
39-
}
40-
4133
/**
4234
* The query to validate.
4335
*

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919

2020
package org.elasticsearch.rest.action.admin.indices;
2121

22-
import org.apache.logging.log4j.LogManager;
2322
import org.elasticsearch.action.admin.indices.validate.query.QueryExplanation;
2423
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
2524
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
2625
import org.elasticsearch.action.support.IndicesOptions;
2726
import org.elasticsearch.client.node.NodeClient;
2827
import org.elasticsearch.common.ParsingException;
2928
import org.elasticsearch.common.Strings;
30-
import org.elasticsearch.common.logging.DeprecationLogger;
3129
import org.elasticsearch.common.xcontent.XContentBuilder;
3230
import org.elasticsearch.rest.BaseRestHandler;
3331
import org.elasticsearch.rest.BytesRestResponse;
@@ -44,18 +42,12 @@
4442
import static org.elasticsearch.rest.RestStatus.OK;
4543

4644
public class RestValidateQueryAction extends BaseRestHandler {
47-
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
48-
LogManager.getLogger(RestValidateQueryAction.class));
49-
static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" +
50-
" Specifying types in validate query requests is deprecated.";
5145

5246
public RestValidateQueryAction(RestController controller) {
5347
controller.registerHandler(GET, "/_validate/query", this);
5448
controller.registerHandler(POST, "/_validate/query", this);
5549
controller.registerHandler(GET, "/{index}/_validate/query", this);
5650
controller.registerHandler(POST, "/{index}/_validate/query", this);
57-
controller.registerHandler(GET, "/{index}/{type}/_validate/query", this);
58-
controller.registerHandler(POST, "/{index}/{type}/_validate/query", this);
5951
}
6052

6153
@Override
@@ -68,12 +60,6 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
6860
ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest(Strings.splitStringByCommaToArray(request.param("index")));
6961
validateQueryRequest.indicesOptions(IndicesOptions.fromRequest(request, validateQueryRequest.indicesOptions()));
7062
validateQueryRequest.explain(request.paramAsBoolean("explain", false));
71-
72-
if (request.hasParam("type")) {
73-
deprecationLogger.deprecatedAndMaybeLog("validate_query_with_types", TYPES_DEPRECATION_MESSAGE);
74-
validateQueryRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
75-
}
76-
7763
validateQueryRequest.rewrite(request.paramAsBoolean("rewrite", false));
7864
validateQueryRequest.allShards(request.paramAsBoolean("all_shards", false));
7965

server/src/test/java/org/elasticsearch/action/ShardValidateQueryRequestTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,12 @@ public void testSerialize() throws IOException {
5555
validateQueryRequest.query(QueryBuilders.termQuery("field", "value"));
5656
validateQueryRequest.rewrite(true);
5757
validateQueryRequest.explain(false);
58-
validateQueryRequest.types("type1", "type2");
5958
ShardValidateQueryRequest request = new ShardValidateQueryRequest(new ShardId("index", "foobar", 1),
60-
new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] {"alias0", "alias1"}), validateQueryRequest);
59+
new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), "alias0", "alias1"), validateQueryRequest);
6160
request.writeTo(output);
6261
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
6362
ShardValidateQueryRequest readRequest = new ShardValidateQueryRequest(in);
6463
assertEquals(request.filteringAliases(), readRequest.filteringAliases());
65-
assertArrayEquals(request.types(), readRequest.types());
6664
assertEquals(request.explain(), readRequest.explain());
6765
assertEquals(request.query(), readRequest.query());
6866
assertEquals(request.rewrite(), readRequest.rewrite());

server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryActionTests.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@
1818
*/
1919
package org.elasticsearch.rest.action.admin.indices;
2020

21-
import org.elasticsearch.action.ActionType;
2221
import org.elasticsearch.action.ActionListener;
2322
import org.elasticsearch.action.ActionRequest;
23+
import org.elasticsearch.action.ActionType;
2424
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryAction;
2525
import org.elasticsearch.action.support.ActionFilters;
2626
import org.elasticsearch.action.support.TransportAction;
2727
import org.elasticsearch.client.node.NodeClient;
2828
import org.elasticsearch.common.bytes.BytesArray;
2929
import org.elasticsearch.common.settings.Settings;
30-
import org.elasticsearch.common.util.concurrent.ThreadContext;
3130
import org.elasticsearch.common.xcontent.XContentType;
3231
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
33-
import org.elasticsearch.rest.RestChannel;
3432
import org.elasticsearch.rest.RestController;
3533
import org.elasticsearch.rest.RestRequest;
3634
import org.elasticsearch.search.AbstractSearchTestCase;
@@ -86,7 +84,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener listen
8684
}
8785

8886
@AfterClass
89-
public static void terminateThreadPool() throws InterruptedException {
87+
public static void terminateThreadPool() {
9088
terminate(threadPool);
9189

9290
threadPool = null;
@@ -153,32 +151,4 @@ private RestRequest createRestRequest(String content) {
153151
.build();
154152
}
155153

156-
public void testTypeInPath() {
157-
RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
158-
.withMethod(RestRequest.Method.GET)
159-
.withPath("/some_index/some_type/_validate/query")
160-
.build();
161-
162-
performRequest(request);
163-
assertWarnings(RestValidateQueryAction.TYPES_DEPRECATION_MESSAGE);
164-
}
165-
166-
public void testTypeParameter() {
167-
Map<String, String> params = new HashMap<>();
168-
params.put("type", "some_type");
169-
RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
170-
.withMethod(RestRequest.Method.GET)
171-
.withPath("_validate/query")
172-
.withParams(params)
173-
.build();
174-
175-
performRequest(request);
176-
assertWarnings(RestValidateQueryAction.TYPES_DEPRECATION_MESSAGE);
177-
}
178-
179-
private void performRequest(RestRequest request) {
180-
RestChannel channel = new FakeRestChannel(request, false, 1);
181-
ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
182-
controller.dispatchRequest(request, channel, threadContext);
183-
}
184154
}

server/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ public void testIrrelevantPropertiesAfterQuery() {
270270

271271
private static void assertExplanation(QueryBuilder queryBuilder, Matcher<String> matcher, boolean withRewrite) {
272272
ValidateQueryResponse response = client().admin().indices().prepareValidateQuery("test")
273-
.setTypes("type1")
274273
.setQuery(queryBuilder)
275274
.setExplain(true)
276275
.setRewrite(withRewrite)
@@ -285,7 +284,6 @@ private static void assertExplanations(QueryBuilder queryBuilder,
285284
List<Matcher<String>> matchers, boolean withRewrite,
286285
boolean allShards) {
287286
ValidateQueryResponse response = client().admin().indices().prepareValidateQuery("test")
288-
.setTypes("type1")
289287
.setQuery(queryBuilder)
290288
.setExplain(true)
291289
.setRewrite(withRewrite)
@@ -309,7 +307,6 @@ public void testExplainTermsQueryWithLookup() {
309307

310308
TermsQueryBuilder termsLookupQuery = QueryBuilders.termsLookupQuery("user", new TermsLookup("twitter", "_doc", "1", "followers"));
311309
ValidateQueryResponse response = client().admin().indices().prepareValidateQuery("twitter")
312-
.setTypes("_doc")
313310
.setQuery(termsLookupQuery)
314311
.setExplain(true)
315312
.execute().actionGet();

0 commit comments

Comments
 (0)