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

This commit is contained in:
Julie Tibshirani 2018-04-27 16:14:11 -07:00 committed by GitHub
parent 9c586a2f07
commit f5978d6d33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 15 additions and 123 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -35,9 +35,6 @@
}
}
},
"body": {
"description": "Field json objects containing an array of field names",
"required": false
}
"body": null
}
}

View File

@ -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
*/

View File

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

View File

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