Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,7 @@ static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) thro

static Request validateQuery(ValidateQueryRequest validateQueryRequest) throws IOException {
String[] indices = validateQueryRequest.indices() == null ? Strings.EMPTY_ARRAY : validateQueryRequest.indices();
String[] types = validateQueryRequest.types() == null || indices.length <= 0 ? Strings.EMPTY_ARRAY : validateQueryRequest.types();
String endpoint = RequestConverters.endpoint(indices, types, "_validate/query");
String endpoint = RequestConverters.endpoint(indices, "_validate/query");
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params();
params.withIndicesOptions(validateQueryRequest.indicesOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1125,15 +1125,13 @@ public void testPutTemplateRequest() throws Exception {
}
public void testValidateQuery() throws Exception {
String[] indices = ESTestCase.randomBoolean() ? null : RequestConvertersTests.randomIndicesNames(0, 5);
String[] types = ESTestCase.randomBoolean() ? ESTestCase.generateRandomStringArray(5, 5, false, false) : null;
ValidateQueryRequest validateQueryRequest;
if (ESTestCase.randomBoolean()) {
validateQueryRequest = new ValidateQueryRequest(indices);
} else {
validateQueryRequest = new ValidateQueryRequest();
validateQueryRequest.indices(indices);
}
validateQueryRequest.types(types);
Map<String, String> expectedParams = new HashMap<>();
RequestConvertersTests.setRandomIndicesOptions(validateQueryRequest::indicesOptions, validateQueryRequest::indicesOptions,
expectedParams);
Expand All @@ -1147,9 +1145,6 @@ public void testValidateQuery() throws Exception {
StringJoiner endpoint = new StringJoiner("/", "/", "");
if (indices != null && indices.length > 0) {
endpoint.add(String.join(",", indices));
if (types != null && types.length > 0) {
endpoint.add(String.join(",", types));
}
}
endpoint.add("_validate/query");
Assert.assertThat(request.getEndpoint(), equalTo(endpoint.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

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

import org.elasticsearch.Version;
import org.elasticsearch.action.support.broadcast.BroadcastShardRequest;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.index.query.QueryBuilder;
Expand All @@ -36,7 +36,6 @@
public class ShardValidateQueryRequest extends BroadcastShardRequest {

private QueryBuilder query;
private String[] types = Strings.EMPTY_ARRAY;
private boolean explain;
private boolean rewrite;
private long nowInMillis;
Expand All @@ -45,12 +44,12 @@ public class ShardValidateQueryRequest extends BroadcastShardRequest {
public ShardValidateQueryRequest(StreamInput in) throws IOException {
super(in);
query = in.readNamedWriteable(QueryBuilder.class);

int typesSize = in.readVInt();
if (typesSize > 0) {
types = new String[typesSize];
for (int i = 0; i < typesSize; i++) {
types[i] = in.readString();
if (in.getVersion().before(Version.V_8_0_0)) {
int typesSize = in.readVInt();
if (typesSize > 0) {
for (int i = 0; i < typesSize; i++) {
in.readString();
}
}
}
filteringAliases = new AliasFilter(in);
Expand All @@ -62,7 +61,6 @@ public ShardValidateQueryRequest(StreamInput in) throws IOException {
public ShardValidateQueryRequest(ShardId shardId, AliasFilter filteringAliases, ValidateQueryRequest request) {
super(shardId, request);
this.query = request.query();
this.types = request.types();
this.explain = request.explain();
this.rewrite = request.rewrite();
this.filteringAliases = Objects.requireNonNull(filteringAliases, "filteringAliases must not be null");
Expand All @@ -73,10 +71,6 @@ public QueryBuilder query() {
return query;
}

public String[] types() {
return this.types;
}

public boolean explain() {
return this.explain;
}
Expand All @@ -97,9 +91,8 @@ public long nowInMillis() {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeNamedWriteable(query);
out.writeVInt(types.length);
for (String type : types) {
out.writeString(type);
if (out.getVersion().before(Version.V_8_0_0)) {
out.writeVInt(0); // no types to filter
}
filteringAliases.writeTo(out);
out.writeBoolean(explain);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

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

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ValidateActions;
import org.elasticsearch.action.support.IndicesOptions;
Expand Down Expand Up @@ -47,8 +48,6 @@ public class ValidateQueryRequest extends BroadcastRequest<ValidateQueryRequest>
private boolean rewrite;
private boolean allShards;

private String[] types = Strings.EMPTY_ARRAY;

long nowInMillis;

public ValidateQueryRequest() {
Expand All @@ -58,11 +57,12 @@ public ValidateQueryRequest() {
public ValidateQueryRequest(StreamInput in) throws IOException {
super(in);
query = in.readNamedWriteable(QueryBuilder.class);
int typesSize = in.readVInt();
if (typesSize > 0) {
types = new String[typesSize];
for (int i = 0; i < typesSize; i++) {
types[i] = in.readString();
if (in.getVersion().before(Version.V_8_0_0)) {
int typesSize = in.readVInt();
if (typesSize > 0) {
for (int i = 0; i < typesSize; i++) {
in.readString();
}
}
}
explain = in.readBoolean();
Expand Down Expand Up @@ -100,29 +100,6 @@ public ValidateQueryRequest query(QueryBuilder query) {
return this;
}

/**
* The types of documents the query will run against. Defaults to 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 this.types;
}

/**
* The types of documents the query will run against. Defaults to 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 ValidateQueryRequest types(String... types) {
this.types = types;
return this;
}

/**
* Indicate if detailed information about query is requested
*/
Expand Down Expand Up @@ -169,9 +146,8 @@ public boolean allShards() {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeNamedWriteable(query);
out.writeVInt(types.length);
for (String type : types) {
out.writeString(type);
if (out.getVersion().before(Version.V_8_0_0)) {
out.writeVInt(0); // no types to filter
}
out.writeBoolean(explain);
out.writeBoolean(rewrite);
Expand All @@ -180,7 +156,7 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public String toString() {
return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types) + ", query[" + query + "], explain:" + explain +
return "[" + Arrays.toString(indices) + "] query[" + query + "], explain:" + explain +
", rewrite:" + rewrite + ", all_shards:" + allShards;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ public ValidateQueryRequestBuilder(ElasticsearchClient client, ValidateQueryActi
super(client, action, new ValidateQueryRequest());
}

/**
* The types of documents the query will run against. Defaults to all types.
*/
public ValidateQueryRequestBuilder setTypes(String... types) {
request.types(types);
return this;
}

/**
* The query to validate.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@

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

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.action.admin.indices.validate.query.QueryExplanation;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
Expand All @@ -44,18 +42,12 @@
import static org.elasticsearch.rest.RestStatus.OK;

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

public RestValidateQueryAction(RestController controller) {
controller.registerHandler(GET, "/_validate/query", this);
controller.registerHandler(POST, "/_validate/query", this);
controller.registerHandler(GET, "/{index}/_validate/query", this);
controller.registerHandler(POST, "/{index}/_validate/query", this);
controller.registerHandler(GET, "/{index}/{type}/_validate/query", this);
controller.registerHandler(POST, "/{index}/{type}/_validate/query", this);
}

@Override
Expand All @@ -68,12 +60,6 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest(Strings.splitStringByCommaToArray(request.param("index")));
validateQueryRequest.indicesOptions(IndicesOptions.fromRequest(request, validateQueryRequest.indicesOptions()));
validateQueryRequest.explain(request.paramAsBoolean("explain", false));

if (request.hasParam("type")) {
deprecationLogger.deprecatedAndMaybeLog("validate_query_with_types", TYPES_DEPRECATION_MESSAGE);
validateQueryRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
}

validateQueryRequest.rewrite(request.paramAsBoolean("rewrite", false));
validateQueryRequest.allShards(request.paramAsBoolean("all_shards", false));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@ public void testSerialize() throws IOException {
validateQueryRequest.query(QueryBuilders.termQuery("field", "value"));
validateQueryRequest.rewrite(true);
validateQueryRequest.explain(false);
validateQueryRequest.types("type1", "type2");
ShardValidateQueryRequest request = new ShardValidateQueryRequest(new ShardId("index", "foobar", 1),
new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] {"alias0", "alias1"}), validateQueryRequest);
new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), "alias0", "alias1"), validateQueryRequest);
request.writeTo(output);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
ShardValidateQueryRequest readRequest = new ShardValidateQueryRequest(in);
assertEquals(request.filteringAliases(), readRequest.filteringAliases());
assertArrayEquals(request.types(), readRequest.types());
assertEquals(request.explain(), readRequest.explain());
assertEquals(request.query(), readRequest.query());
assertEquals(request.rewrite(), readRequest.rewrite());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@
*/
package org.elasticsearch.rest.action.admin.indices;

import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryAction;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.TransportAction;
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.search.AbstractSearchTestCase;
Expand Down Expand Up @@ -86,7 +84,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener listen
}

@AfterClass
public static void terminateThreadPool() throws InterruptedException {
public static void terminateThreadPool() {
terminate(threadPool);

threadPool = null;
Expand Down Expand Up @@ -153,32 +151,4 @@ private RestRequest createRestRequest(String content) {
.build();
}

public void testTypeInPath() {
RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
.withMethod(RestRequest.Method.GET)
.withPath("/some_index/some_type/_validate/query")
.build();

performRequest(request);
assertWarnings(RestValidateQueryAction.TYPES_DEPRECATION_MESSAGE);
}

public void testTypeParameter() {
Map<String, String> params = new HashMap<>();
params.put("type", "some_type");
RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
.withMethod(RestRequest.Method.GET)
.withPath("_validate/query")
.withParams(params)
.build();

performRequest(request);
assertWarnings(RestValidateQueryAction.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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ public void testIrrelevantPropertiesAfterQuery() {

private static void assertExplanation(QueryBuilder queryBuilder, Matcher<String> matcher, boolean withRewrite) {
ValidateQueryResponse response = client().admin().indices().prepareValidateQuery("test")
.setTypes("type1")
.setQuery(queryBuilder)
.setExplain(true)
.setRewrite(withRewrite)
Expand All @@ -285,7 +284,6 @@ private static void assertExplanations(QueryBuilder queryBuilder,
List<Matcher<String>> matchers, boolean withRewrite,
boolean allShards) {
ValidateQueryResponse response = client().admin().indices().prepareValidateQuery("test")
.setTypes("type1")
.setQuery(queryBuilder)
.setExplain(true)
.setRewrite(withRewrite)
Expand All @@ -309,7 +307,6 @@ public void testExplainTermsQueryWithLookup() {

TermsQueryBuilder termsLookupQuery = QueryBuilders.termsLookupQuery("user", new TermsLookup("twitter", "_doc", "1", "followers"));
ValidateQueryResponse response = client().admin().indices().prepareValidateQuery("twitter")
.setTypes("_doc")
.setQuery(termsLookupQuery)
.setExplain(true)
.execute().actionGet();
Expand Down