Skip to content

Commit

Permalink
Deprecate types in validate query requests. (#35575)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtibshirani authored Nov 16, 2018
1 parent 6a8fe49 commit 40ba4de
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
10 changes: 5 additions & 5 deletions docs/reference/search/validate.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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" : {
Expand All @@ -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": {
Expand All @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

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.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
Expand All @@ -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);
Expand All @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

/**
Expand Down Expand Up @@ -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<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);
}
}

0 comments on commit 40ba4de

Please sign in to comment.