From 781cf9a49aad021eb8659ddfcd712d66873be840 Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Wed, 25 Apr 2018 11:53:35 -0700 Subject: [PATCH 1/2] In the field capabilities API, remove support for providing fields in the request body. --- docs/reference/migration/migrate_6_4.asciidoc | 12 ---- .../migration/migrate_7_0/api.asciidoc | 7 +++ docs/reference/search/field-caps.asciidoc | 14 ----- .../rest-api-spec/api/field_caps.json | 5 +- .../fieldcaps/FieldCapabilitiesRequest.java | 5 -- .../action/RestFieldCapabilitiesAction.java | 34 ++--------- .../RestFieldCapabilitiesActionTests.java | 59 ------------------- 7 files changed, 13 insertions(+), 123 deletions(-) delete mode 100644 docs/reference/migration/migrate_6_4.asciidoc delete mode 100644 server/src/test/java/org/elasticsearch/rest/action/RestFieldCapabilitiesActionTests.java diff --git a/docs/reference/migration/migrate_6_4.asciidoc b/docs/reference/migration/migrate_6_4.asciidoc deleted file mode 100644 index a761509597fd2..0000000000000 --- a/docs/reference/migration/migrate_6_4.asciidoc +++ /dev/null @@ -1,12 +0,0 @@ -[[breaking-changes-6.4]] -== Breaking changes in 6.4 - -[[breaking_64_api_changes]] -=== API changes - -==== Field capabilities request format - -In the past, `fields` could be provided either as a parameter, or as part of the request -body. Specifying `fields` in the request body is now deprecated, and instead they should -always be supplied through a request parameter. In 7.0.0, the field capabilities API will -not accept `fields` supplied in the request body. diff --git a/docs/reference/migration/migrate_7_0/api.asciidoc b/docs/reference/migration/migrate_7_0/api.asciidoc index 2da822a7e5e62..6a171ee63b54a 100644 --- a/docs/reference/migration/migrate_7_0/api.asciidoc +++ b/docs/reference/migration/migrate_7_0/api.asciidoc @@ -33,3 +33,10 @@ Previously, `suggest` stats were folded into `search` stats. Support for the `suggest` metric on the indices stats and nodes stats APIs remained for backwards compatibility. Backwards support for the `suggest` metric was deprecated in 6.3.0 and now removed in 7.0.0. + +[[remove-field-caps-body]] +==== In the fields capabilities API, `fields` can no longer be provided in the request body. + +In the past, `fields` could be provided either as a parameter, or as part of the request +body. Specifying `fields` in the request body as opposed to a parameter was deprecated +in 6.4.0, and is now unsupported in 7.0.0. diff --git a/docs/reference/search/field-caps.asciidoc b/docs/reference/search/field-caps.asciidoc index 6cb483e7a256e..1df2279c26caf 100644 --- a/docs/reference/search/field-caps.asciidoc +++ b/docs/reference/search/field-caps.asciidoc @@ -20,20 +20,6 @@ GET twitter/_field_caps?fields=rating // CONSOLE // TEST[setup:twitter] -Alternatively the `fields` option can also be defined in the request body. deprecated[6.4.0, Please use a request parameter instead.] - -[source,js] --------------------------------------------------- -POST _field_caps -{ - "fields" : ["rating"] -} --------------------------------------------------- -// CONSOLE -// TEST[warning:Specifying a request body is deprecated -- the [fields] request parameter should be used instead.] - -This is equivalent to the previous request. - Supported request options: [horizontal] diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/field_caps.json b/rest-api-spec/src/main/resources/rest-api-spec/api/field_caps.json index d993dc0545b74..3ba09ca314b03 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/field_caps.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/field_caps.json @@ -35,9 +35,6 @@ } } }, - "body": { - "description": "Field json objects containing an array of field names", - "required": false - } + "body": null } } \ No newline at end of file diff --git a/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java b/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java index e91d9a703f491..636af6101ae0e 100644 --- a/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java +++ b/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; -import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; import java.util.Arrays; @@ -102,10 +101,6 @@ public void writeTo(StreamOutput out) throws IOException { } } - public static FieldCapabilitiesRequest parseFields(XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } - /** * The list of field names to retrieve */ diff --git a/server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java b/server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java index 4c477334265f6..4b9d37ace91c6 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java @@ -20,25 +20,18 @@ package org.elasticsearch.rest.action; import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest; -import org.elasticsearch.action.fieldcaps.FieldCapabilitiesResponse; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.RestResponse; -import org.elasticsearch.rest.RestStatus; import java.io.IOException; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; -import static org.elasticsearch.rest.RestStatus.OK; public class RestFieldCapabilitiesAction extends BaseRestHandler { public RestFieldCapabilitiesAction(Settings settings, RestController controller) { @@ -57,30 +50,13 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { - if (request.hasContentOrSourceParam()) { - deprecationLogger.deprecated("Specifying a request body is deprecated -- the" + - " [fields] request parameter should be used instead."); - if (request.hasParam("fields")) { - throw new IllegalArgumentException("can't specify a request body and [fields]" + - " request parameter, either specify a request body or the" + - " [fields] request parameter"); - } - } + String[] indices = Strings.splitStringByCommaToArray(request.param("index")); + FieldCapabilitiesRequest fieldRequest = new FieldCapabilitiesRequest() + .fields(Strings.splitStringByCommaToArray(request.param("fields"))) + .indices(indices); - final String[] indices = Strings.splitStringByCommaToArray(request.param("index")); - final FieldCapabilitiesRequest fieldRequest; - if (request.hasContentOrSourceParam()) { - try (XContentParser parser = request.contentOrSourceParamParser()) { - fieldRequest = FieldCapabilitiesRequest.parseFields(parser); - } - } else { - fieldRequest = new FieldCapabilitiesRequest(); - fieldRequest.fields(Strings.splitStringByCommaToArray(request.param("fields"))); - } - fieldRequest.indices(indices); fieldRequest.indicesOptions( - IndicesOptions.fromRequest(request, fieldRequest.indicesOptions()) - ); + IndicesOptions.fromRequest(request, fieldRequest.indicesOptions())); return channel -> client.fieldCaps(fieldRequest, new RestToXContentListener<>(channel)); } } diff --git a/server/src/test/java/org/elasticsearch/rest/action/RestFieldCapabilitiesActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/RestFieldCapabilitiesActionTests.java deleted file mode 100644 index b8dd007f56729..0000000000000 --- a/server/src/test/java/org/elasticsearch/rest/action/RestFieldCapabilitiesActionTests.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.rest.action; - -import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.action.RestFieldCapabilitiesAction; -import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.rest.FakeRestRequest; -import org.elasticsearch.usage.UsageService; -import org.junit.Before; - -import java.io.IOException; -import java.util.Collections; - -import static org.mockito.Mockito.mock; - -public class RestFieldCapabilitiesActionTests extends ESTestCase { - - private RestFieldCapabilitiesAction action; - - @Before - public void setUpAction() { - action = new RestFieldCapabilitiesAction(Settings.EMPTY, mock(RestController.class)); - } - - public void testRequestBodyIsDeprecated() throws IOException { - String content = "{ \"fields\": [\"title\"] }"; - RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) - .withPath("/_field_caps") - .withContent(new BytesArray(content), XContentType.JSON) - .build(); - action.prepareRequest(request, mock(NodeClient.class)); - - assertWarnings("Specifying a request body is deprecated -- the" + - " [fields] request parameter should be used instead."); - } -} From 890c48db64c02ee689367f3816b1c145a642f237 Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Thu, 26 Apr 2018 13:36:03 -0700 Subject: [PATCH 2/2] Update the changelog. --- docs/CHANGELOG.asciidoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/CHANGELOG.asciidoc b/docs/CHANGELOG.asciidoc index 6fb989de7c1be..a685ddf2b5178 100644 --- a/docs/CHANGELOG.asciidoc +++ b/docs/CHANGELOG.asciidoc @@ -14,6 +14,8 @@ <> ({pull}29635[#29635]) +<> ({pull}30185[#30185]) + === Breaking Java Changes === Deprecations