Skip to content

Commit

Permalink
Fix types deprecation warning for put mapping. (#58764)
Browse files Browse the repository at this point in the history
In #38825, we switched from issuing a types warning if `include_type_name` is
missing or `true`, to only issuing a warning when `include_type_name` is
missing. However we missed the 'put mapping' API in that PR.

Addresses #58675.
  • Loading branch information
jtibshirani committed Jun 30, 2020
1 parent 6bb49ed commit f57743e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
public class RestPutMappingAction extends BaseRestHandler {
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
LogManager.getLogger(RestPutMappingAction.class));
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in put mapping " +
"requests is deprecated. To be compatible with 7.0, the mapping definition should not be nested under " +
"the type name, and the parameter include_type_name must be provided and set to false.";
static final String TYPES_DEPRECATION_MESSAGE = "[types removal] The parameter include_type_name " +
"should be explicitly specified in put mapping requests to prepare for 7.0. In 7.0 include_type_name " +
"will default to 'false', and requests are expected to omit the type name in mapping definitions.";

public RestPutMappingAction(Settings settings, RestController controller) {
super(settings);
Expand Down Expand Up @@ -81,15 +81,17 @@ public String getName() {
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index")));

boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER,
DEFAULT_INCLUDE_TYPE_NAME_POLICY);
String type = request.param("type");
Map<String, Object> sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false,
request.getXContentType()).v2();

if (includeTypeName) {
if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER) == false) {
deprecationLogger.deprecatedAndMaybeLog("put_mapping_with_types", TYPES_DEPRECATION_MESSAGE);
} else if (type != null || isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, sourceAsMap)) {
}

boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER,
DEFAULT_INCLUDE_TYPE_NAME_POLICY);
if (includeTypeName == false && (type != null || isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, sourceAsMap))) {
throw new IllegalArgumentException("Types cannot be provided in put mapping requests, unless " +
"the include_type_name parameter is set to true.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void testIncludeTypeName() throws Exception {
assertWarnings(RestPutMappingAction.TYPES_DEPRECATION_MESSAGE);

Map<String, String> params = new HashMap<>();
params.put(INCLUDE_TYPE_NAME_PARAMETER, "false");
params.put(INCLUDE_TYPE_NAME_PARAMETER, randomFrom("true", "false"));
RestRequest validRequest = new FakeRestRequest.Builder(xContentRegistry())
.withMethod(RestRequest.Method.PUT)
.withPath("/some_index/_mapping")
Expand Down

0 comments on commit f57743e

Please sign in to comment.