Browse Source

In the field capabilities API, remove support for providing fields in the request body. (#30185)

Julie Tibshirani 7 years ago
parent
commit
f5978d6d33

+ 2 - 0
docs/CHANGELOG.asciidoc

@@ -14,6 +14,8 @@
 
 <<remove-suggest-metric, Removed `suggest` metric on stats APIs>> ({pull}29635[#29635])
 
+<<remove-field-caps-body, In field capabilities APIs, removed support for providing fields in the request body>> ({pull}30185[#30185])
+
 === Breaking Java Changes
 
 === Deprecations

+ 0 - 12
docs/reference/migration/migrate_6_4.asciidoc

@@ -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.

+ 7 - 0
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.

+ 0 - 14
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]

+ 1 - 4
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
   }
 }

+ 0 - 5
server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java

@@ -30,7 +30,6 @@ import org.elasticsearch.common.Strings;
 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 final class FieldCapabilitiesRequest extends ActionRequest implements Ind
         }
     }
 
-    public static FieldCapabilitiesRequest parseFields(XContentParser parser) throws IOException {
-        return PARSER.parse(parser, null);
-    }
-
     /**
      * The list of field names to retrieve
      */

+ 5 - 29
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 class RestFieldCapabilitiesAction extends BaseRestHandler {
     @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));
     }
 }

+ 0 - 59
server/src/test/java/org/elasticsearch/rest/action/RestFieldCapabilitiesActionTests.java

@@ -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.");
-    }
-}