diff --git a/docs/reference/search/validate.asciidoc b/docs/reference/search/validate.asciidoc index c05a0cb55646e..c17f1393e1520 100644 --- a/docs/reference/search/validate.asciidoc +++ b/docs/reference/search/validate.asciidoc @@ -60,7 +60,7 @@ The query may also be sent in the request body: [source,js] -------------------------------------------------- -GET twitter/_doc/_validate/query +GET twitter/_validate/query { "query" : { "bool" : { @@ -87,7 +87,7 @@ due to dynamic mapping, and 'foo' does not correctly parse into a date: [source,js] -------------------------------------------------- -GET twitter/_doc/_validate/query +GET twitter/_validate/query { "query": { "query_string": { @@ -110,7 +110,7 @@ about why a query failed: [source,js] -------------------------------------------------- -GET twitter/_doc/_validate/query?explain=true +GET twitter/_validate/query?explain=true { "query": { "query_string": { @@ -150,7 +150,7 @@ For More Like This: [source,js] -------------------------------------------------- -GET twitter/_doc/_validate/query?rewrite=true +GET twitter/_validate/query?rewrite=true { "query": { "more_like_this": { @@ -197,7 +197,7 @@ For Fuzzy Queries: [source,js] -------------------------------------------------- -GET twitter/_doc/_validate/query?rewrite=true&all_shards=true +GET twitter/_validate/query?rewrite=true&all_shards=true { "query": { "match": { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequest.java index a30c9ba846107..4f993e40d0b8b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryRequest.java @@ -87,14 +87,22 @@ public ValidateQueryRequest query(QueryBuilder query) { /** * 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; diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java index d1a97d74d047f..3486a5a4cb51b 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java @@ -19,6 +19,7 @@ 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; @@ -26,6 +27,7 @@ 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.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; @@ -43,6 +45,11 @@ 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(Settings settings, RestController controller) { super(settings); controller.registerHandler(GET, "/_validate/query", this); @@ -63,7 +70,12 @@ 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)); - validateQueryRequest.types(Strings.splitStringByCommaToArray(request.param("type"))); + + if (request.hasParam("type")) { + deprecationLogger.deprecated(TYPES_DEPRECATION_MESSAGE); + validateQueryRequest.types(Strings.splitStringByCommaToArray(request.param("type"))); + } + validateQueryRequest.rewrite(request.paramAsBoolean("rewrite", false)); validateQueryRequest.allShards(request.paramAsBoolean("all_shards", false)); diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryActionTests.java index da31e3ad13e6e..0d2e4723a7352 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryActionTests.java @@ -27,7 +27,10 @@ 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; @@ -56,7 +59,8 @@ public class RestValidateQueryActionTests extends AbstractSearchTestCase { private static NodeClient client = new NodeClient(Settings.EMPTY, threadPool); private static UsageService usageService = new UsageService(); - private static RestController controller = new RestController(emptySet(), null, client, null, usageService); + private static RestController controller = new RestController(emptySet(), null, client, + new NoneCircuitBreakerService(), usageService); private static RestValidateQueryAction action = new RestValidateQueryAction(Settings.EMPTY, controller); /** @@ -148,4 +152,33 @@ private RestRequest createRestRequest(String content) { .withContent(new BytesArray(content), XContentType.JSON) .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 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); + } }