Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 5b0da85

Browse files
authored
Remove type from validate query API (opensearch-project#2255)
* Remove type mapping from RestValidateAction Signed-off-by: Suraj Singh <[email protected]> * Spotless check apply Signed-off-by: Suraj Singh <[email protected]> * Include suggested review comment Signed-off-by: Suraj Singh <[email protected]>
1 parent 494c7bc commit 5b0da85

File tree

8 files changed

+22
-84
lines changed

8 files changed

+22
-84
lines changed

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,7 @@ static Request simulateIndexTemplate(SimulateIndexTemplateRequest simulateIndexT
669669

670670
static Request validateQuery(ValidateQueryRequest validateQueryRequest) throws IOException {
671671
String[] indices = validateQueryRequest.indices() == null ? Strings.EMPTY_ARRAY : validateQueryRequest.indices();
672-
String[] types = validateQueryRequest.types() == null || indices.length <= 0 ? Strings.EMPTY_ARRAY : validateQueryRequest.types();
673-
String endpoint = RequestConverters.endpoint(indices, types, "_validate/query");
672+
String endpoint = RequestConverters.endpoint(indices, "_validate/query");
674673
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
675674
RequestConverters.Params params = new RequestConverters.Params();
676675
params.withIndicesOptions(validateQueryRequest.indicesOptions());

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

-5
Original file line numberDiff line numberDiff line change
@@ -1198,15 +1198,13 @@ public void testPutTemplateRequest() throws Exception {
11981198

11991199
public void testValidateQuery() throws Exception {
12001200
String[] indices = OpenSearchTestCase.randomBoolean() ? null : RequestConvertersTests.randomIndicesNames(0, 5);
1201-
String[] types = OpenSearchTestCase.randomBoolean() ? OpenSearchTestCase.generateRandomStringArray(5, 5, false, false) : null;
12021201
ValidateQueryRequest validateQueryRequest;
12031202
if (OpenSearchTestCase.randomBoolean()) {
12041203
validateQueryRequest = new ValidateQueryRequest(indices);
12051204
} else {
12061205
validateQueryRequest = new ValidateQueryRequest();
12071206
validateQueryRequest.indices(indices);
12081207
}
1209-
validateQueryRequest.types(types);
12101208
Map<String, String> expectedParams = new HashMap<>();
12111209
RequestConvertersTests.setRandomIndicesOptions(
12121210
validateQueryRequest::indicesOptions,
@@ -1223,9 +1221,6 @@ public void testValidateQuery() throws Exception {
12231221
StringJoiner endpoint = new StringJoiner("/", "/", "");
12241222
if (indices != null && indices.length > 0) {
12251223
endpoint.add(String.join(",", indices));
1226-
if (types != null && types.length > 0) {
1227-
endpoint.add(String.join(",", types));
1228-
}
12291224
}
12301225
endpoint.add("_validate/query");
12311226
Assert.assertThat(request.getEndpoint(), equalTo(endpoint.toString()));

server/src/internalClusterTest/java/org/opensearch/validate/SimpleValidateQueryIT.java

-3
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ private static void assertExplanation(QueryBuilder queryBuilder, Matcher<String>
447447
ValidateQueryResponse response = client().admin()
448448
.indices()
449449
.prepareValidateQuery("test")
450-
.setTypes("type1")
451450
.setQuery(queryBuilder)
452451
.setExplain(true)
453452
.setRewrite(withRewrite)
@@ -468,7 +467,6 @@ private static void assertExplanations(
468467
ValidateQueryResponse response = client().admin()
469468
.indices()
470469
.prepareValidateQuery("test")
471-
.setTypes("type1")
472470
.setQuery(queryBuilder)
473471
.setExplain(true)
474472
.setRewrite(withRewrite)
@@ -497,7 +495,6 @@ public void testExplainTermsQueryWithLookup() throws Exception {
497495
ValidateQueryResponse response = client().admin()
498496
.indices()
499497
.prepareValidateQuery("twitter")
500-
.setTypes("_doc")
501498
.setQuery(termsLookupQuery)
502499
.setExplain(true)
503500
.execute()

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

+9-16
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
package org.opensearch.action.admin.indices.validate.query;
3434

35+
import org.opensearch.Version;
3536
import org.opensearch.action.support.broadcast.BroadcastShardRequest;
36-
import org.opensearch.common.Strings;
3737
import org.opensearch.common.io.stream.StreamInput;
3838
import org.opensearch.common.io.stream.StreamOutput;
3939
import org.opensearch.index.query.QueryBuilder;
@@ -49,7 +49,6 @@
4949
public class ShardValidateQueryRequest extends BroadcastShardRequest {
5050

5151
private QueryBuilder query;
52-
private String[] types = Strings.EMPTY_ARRAY;
5352
private boolean explain;
5453
private boolean rewrite;
5554
private long nowInMillis;
@@ -58,12 +57,12 @@ public class ShardValidateQueryRequest extends BroadcastShardRequest {
5857
public ShardValidateQueryRequest(StreamInput in) throws IOException {
5958
super(in);
6059
query = in.readNamedWriteable(QueryBuilder.class);
61-
62-
int typesSize = in.readVInt();
63-
if (typesSize > 0) {
64-
types = new String[typesSize];
65-
for (int i = 0; i < typesSize; i++) {
66-
types[i] = in.readString();
60+
if (in.getVersion().before(Version.V_2_0_0)) {
61+
int typesSize = in.readVInt();
62+
if (typesSize > 0) {
63+
for (int i = 0; i < typesSize; i++) {
64+
in.readString();
65+
}
6766
}
6867
}
6968
filteringAliases = new AliasFilter(in);
@@ -75,7 +74,6 @@ public ShardValidateQueryRequest(StreamInput in) throws IOException {
7574
public ShardValidateQueryRequest(ShardId shardId, AliasFilter filteringAliases, ValidateQueryRequest request) {
7675
super(shardId, request);
7776
this.query = request.query();
78-
this.types = request.types();
7977
this.explain = request.explain();
8078
this.rewrite = request.rewrite();
8179
this.filteringAliases = Objects.requireNonNull(filteringAliases, "filteringAliases must not be null");
@@ -86,10 +84,6 @@ public QueryBuilder query() {
8684
return query;
8785
}
8886

89-
public String[] types() {
90-
return this.types;
91-
}
92-
9387
public boolean explain() {
9488
return this.explain;
9589
}
@@ -110,9 +104,8 @@ public long nowInMillis() {
110104
public void writeTo(StreamOutput out) throws IOException {
111105
super.writeTo(out);
112106
out.writeNamedWriteable(query);
113-
out.writeVInt(types.length);
114-
for (String type : types) {
115-
out.writeString(type);
107+
if (out.getVersion().before(Version.V_2_0_0)) {
108+
out.writeVInt(0); // no types to filter
116109
}
117110
filteringAliases.writeTo(out);
118111
out.writeBoolean(explain);

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

+10-35
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
package org.opensearch.action.admin.indices.validate.query;
3434

35+
import org.opensearch.Version;
3536
import org.opensearch.action.ActionRequestValidationException;
3637
import org.opensearch.action.ValidateActions;
3738
import org.opensearch.action.support.IndicesOptions;
@@ -60,8 +61,6 @@ public class ValidateQueryRequest extends BroadcastRequest<ValidateQueryRequest>
6061
private boolean rewrite;
6162
private boolean allShards;
6263

63-
private String[] types = Strings.EMPTY_ARRAY;
64-
6564
long nowInMillis;
6665

6766
public ValidateQueryRequest() {
@@ -71,11 +70,12 @@ public ValidateQueryRequest() {
7170
public ValidateQueryRequest(StreamInput in) throws IOException {
7271
super(in);
7372
query = in.readNamedWriteable(QueryBuilder.class);
74-
int typesSize = in.readVInt();
75-
if (typesSize > 0) {
76-
types = new String[typesSize];
77-
for (int i = 0; i < typesSize; i++) {
78-
types[i] = in.readString();
73+
if (in.getVersion().before(Version.V_2_0_0)) {
74+
int typesSize = in.readVInt();
75+
if (typesSize > 0) {
76+
for (int i = 0; i < typesSize; i++) {
77+
in.readString();
78+
}
7979
}
8080
}
8181
explain = in.readBoolean();
@@ -113,29 +113,6 @@ public ValidateQueryRequest query(QueryBuilder query) {
113113
return this;
114114
}
115115

116-
/**
117-
* The types of documents the query will run against. Defaults to all types.
118-
*
119-
* @deprecated Types are in the process of being removed. Instead of using a type, prefer to
120-
* filter on a field on the document.
121-
*/
122-
@Deprecated
123-
public String[] types() {
124-
return this.types;
125-
}
126-
127-
/**
128-
* The types of documents the query will run against. Defaults to all types.
129-
*
130-
* @deprecated Types are in the process of being removed. Instead of using a type, prefer to
131-
* filter on a field on the document.
132-
*/
133-
@Deprecated
134-
public ValidateQueryRequest types(String... types) {
135-
this.types = types;
136-
return this;
137-
}
138-
139116
/**
140117
* Indicate if detailed information about query is requested
141118
*/
@@ -182,9 +159,8 @@ public boolean allShards() {
182159
public void writeTo(StreamOutput out) throws IOException {
183160
super.writeTo(out);
184161
out.writeNamedWriteable(query);
185-
out.writeVInt(types.length);
186-
for (String type : types) {
187-
out.writeString(type);
162+
if (out.getVersion().before(Version.V_2_0_0)) {
163+
out.writeVInt(0); // no types to filter
188164
}
189165
out.writeBoolean(explain);
190166
out.writeBoolean(rewrite);
@@ -196,8 +172,7 @@ public String toString() {
196172
return "["
197173
+ Arrays.toString(indices)
198174
+ "]"
199-
+ Arrays.toString(types)
200-
+ ", query["
175+
+ " query["
201176
+ query
202177
+ "], explain:"
203178
+ explain

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

-8
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ public ValidateQueryRequestBuilder(OpenSearchClient client, ValidateQueryAction
4545
super(client, action, new ValidateQueryRequest());
4646
}
4747

48-
/**
49-
* The types of documents the query will run against. Defaults to all types.
50-
*/
51-
public ValidateQueryRequestBuilder setTypes(String... types) {
52-
request.types(types);
53-
return this;
54-
}
55-
5648
/**
5749
* The query to validate.
5850
*

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.opensearch.client.node.NodeClient;
4040
import org.opensearch.common.ParsingException;
4141
import org.opensearch.common.Strings;
42-
import org.opensearch.common.logging.DeprecationLogger;
4342
import org.opensearch.common.xcontent.XContentBuilder;
4443
import org.opensearch.rest.BaseRestHandler;
4544
import org.opensearch.rest.BytesRestResponse;
@@ -58,19 +57,14 @@
5857
import static org.opensearch.rest.RestStatus.OK;
5958

6059
public class RestValidateQueryAction extends BaseRestHandler {
61-
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestValidateQueryAction.class);
62-
static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" + " Specifying types in validate query requests is deprecated.";
63-
6460
@Override
6561
public List<Route> routes() {
6662
return unmodifiableList(
6763
asList(
6864
new Route(GET, "/_validate/query"),
6965
new Route(POST, "/_validate/query"),
7066
new Route(GET, "/{index}/_validate/query"),
71-
new Route(POST, "/{index}/_validate/query"),
72-
new Route(GET, "/{index}/{type}/_validate/query"),
73-
new Route(POST, "/{index}/{type}/_validate/query")
67+
new Route(POST, "/{index}/_validate/query")
7468
)
7569
);
7670
}
@@ -86,11 +80,6 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
8680
validateQueryRequest.indicesOptions(IndicesOptions.fromRequest(request, validateQueryRequest.indicesOptions()));
8781
validateQueryRequest.explain(request.paramAsBoolean("explain", false));
8882

89-
if (request.hasParam("type")) {
90-
deprecationLogger.deprecate("validate_query_with_types", TYPES_DEPRECATION_MESSAGE);
91-
validateQueryRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
92-
}
93-
9483
validateQueryRequest.rewrite(request.paramAsBoolean("rewrite", false));
9584
validateQueryRequest.allShards(request.paramAsBoolean("all_shards", false));
9685

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,15 @@ public void testSerialize() throws IOException {
6969
validateQueryRequest.query(QueryBuilders.termQuery("field", "value"));
7070
validateQueryRequest.rewrite(true);
7171
validateQueryRequest.explain(false);
72-
validateQueryRequest.types("type1", "type2");
7372
ShardValidateQueryRequest request = new ShardValidateQueryRequest(
7473
new ShardId("index", "foobar", 1),
75-
new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] { "alias0", "alias1" }),
74+
new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), "alias0", "alias1"),
7675
validateQueryRequest
7776
);
7877
request.writeTo(output);
7978
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
8079
ShardValidateQueryRequest readRequest = new ShardValidateQueryRequest(in);
8180
assertEquals(request.filteringAliases(), readRequest.filteringAliases());
82-
assertArrayEquals(request.types(), readRequest.types());
8381
assertEquals(request.explain(), readRequest.explain());
8482
assertEquals(request.query(), readRequest.query());
8583
assertEquals(request.rewrite(), readRequest.rewrite());

0 commit comments

Comments
 (0)