diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index b5459e7ab53a9..be89d847309cd 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -67,9 +67,9 @@ import org.elasticsearch.client.indices.GetIndexRequest; import org.elasticsearch.client.indices.GetIndexResponse; import org.elasticsearch.client.indices.GetIndexTemplatesRequest; +import org.elasticsearch.client.indices.GetIndexTemplatesResponse; import org.elasticsearch.client.indices.GetMappingsRequest; import org.elasticsearch.client.indices.GetMappingsResponse; -import org.elasticsearch.client.indices.GetIndexTemplatesResponse; import org.elasticsearch.client.indices.IndexTemplateMetaData; import org.elasticsearch.client.indices.IndexTemplatesExistRequest; import org.elasticsearch.client.indices.PutIndexTemplateRequest; @@ -96,14 +96,6 @@ import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.rest.action.admin.indices.RestCreateIndexAction; -import org.elasticsearch.rest.action.admin.indices.RestGetFieldMappingAction; -import org.elasticsearch.rest.action.admin.indices.RestGetIndicesAction; -import org.elasticsearch.rest.action.admin.indices.RestGetMappingAction; -import org.elasticsearch.rest.action.admin.indices.RestPutMappingAction; -import org.elasticsearch.rest.action.admin.indices.RestRolloverIndexAction; -import org.elasticsearch.rest.action.admin.indices.RestGetIndexTemplateAction; -import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction; import java.io.IOException; import java.util.Arrays; @@ -306,8 +298,7 @@ public void testCreateIndexWithTypes() throws IOException { org.elasticsearch.action.admin.indices.create.CreateIndexResponse createIndexResponse = execute( createIndexRequest, highLevelClient().indices()::create, - highLevelClient().indices()::createAsync, - expectWarnings(shardsWarning, RestCreateIndexAction.TYPES_DEPRECATION_MESSAGE)); + highLevelClient().indices()::createAsync); assertTrue(createIndexResponse.isAcknowledged()); Map getIndexResponse = getAsMap(indexName); @@ -474,8 +465,7 @@ public void testGetIndexWithTypes() throws IOException { org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest = new org.elasticsearch.action.admin.indices.get.GetIndexRequest().indices(indexName).includeDefaults(false); org.elasticsearch.action.admin.indices.get.GetIndexResponse getIndexResponse = execute(getIndexRequest, - highLevelClient().indices()::get, highLevelClient().indices()::getAsync, - expectWarnings(RestGetIndicesAction.TYPES_DEPRECATION_MESSAGE)); + highLevelClient().indices()::get, highLevelClient().indices()::getAsync); // default settings should be null assertNull(getIndexResponse.getSetting(indexName, "index.refresh_interval")); @@ -563,8 +553,7 @@ public void testPutMappingWithTypes() throws IOException { AcknowledgedResponse putMappingResponse = execute(putMappingRequest, highLevelClient().indices()::putMapping, - highLevelClient().indices()::putMappingAsync, - expectWarnings(RestPutMappingAction.TYPES_DEPRECATION_MESSAGE)); + highLevelClient().indices()::putMappingAsync); assertTrue(putMappingResponse.isAcknowledged()); Map getIndexResponse = getAsMap(indexName); @@ -636,8 +625,7 @@ public void testGetMappingWithTypes() throws IOException { org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse getMappingsResponse = execute( request, highLevelClient().indices()::getMapping, - highLevelClient().indices()::getMappingAsync, - expectWarnings(RestGetMappingAction.TYPES_DEPRECATION_MESSAGE)); + highLevelClient().indices()::getMappingAsync); Map mappings = getMappingsResponse.getMappings().get(indexName).get("_doc").sourceAsMap(); Map type = new HashMap<>(); @@ -706,8 +694,7 @@ public void testGetFieldMappingWithTypes() throws IOException { org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse getFieldMappingsResponse = execute(getFieldMappingsRequest, highLevelClient().indices()::getFieldMapping, - highLevelClient().indices()::getFieldMappingAsync, - expectWarnings(RestGetFieldMappingAction.TYPES_DEPRECATION_MESSAGE)); + highLevelClient().indices()::getFieldMappingAsync); final Map fieldMappingMap = getFieldMappingsResponse.mappings().get(indexName).get("_doc"); @@ -1215,9 +1202,8 @@ public void testRolloverWithTypes() throws IOException { org.elasticsearch.action.admin.indices.rollover.RolloverResponse rolloverResponse = execute( rolloverRequest, highLevelClient().indices()::rollover, - highLevelClient().indices()::rolloverAsync, - expectWarnings(RestRolloverIndexAction.TYPES_DEPRECATION_MESSAGE) - ); + highLevelClient().indices()::rolloverAsync); + assertTrue(rolloverResponse.isRolledOver()); assertFalse(rolloverResponse.isDryRun()); Map conditionStatus = rolloverResponse.getConditionStatus(); @@ -1528,9 +1514,7 @@ public void testPutTemplateWithTypes() throws Exception { .alias(new Alias("alias-1").indexRouting("abc")).alias(new Alias("{index}-write").searchRouting("xyz")); AcknowledgedResponse putTemplateResponse = execute(putTemplateRequest, - highLevelClient().indices()::putTemplate, highLevelClient().indices()::putTemplateAsync, - expectWarnings(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE) - ); + highLevelClient().indices()::putTemplate, highLevelClient().indices()::putTemplateAsync); assertThat(putTemplateResponse.isAcknowledged(), equalTo(true)); Map templates = getAsMap("/_template/my-template"); @@ -1616,9 +1600,7 @@ public void testPutTemplateWithNoTypesUsingTypedApi() throws Exception { .alias(new Alias("alias-1").indexRouting("abc")).alias(new Alias("{index}-write").searchRouting("xyz")); AcknowledgedResponse putTemplateResponse = execute(putTemplateRequest, - highLevelClient().indices()::putTemplate, highLevelClient().indices()::putTemplateAsync, - expectWarnings(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE) - ); + highLevelClient().indices()::putTemplate, highLevelClient().indices()::putTemplateAsync); assertThat(putTemplateResponse.isAcknowledged(), equalTo(true)); Map templates = getAsMap("/_template/my-template"); @@ -1703,22 +1685,19 @@ public void testCRUDIndexTemplateWithTypes() throws Exception { org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putTemplate1 = new org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest().name("template-1") .patterns(Arrays.asList("pattern-1", "name-1")).alias(new Alias("alias-1")); - assertThat(execute(putTemplate1, client.indices()::putTemplate, client.indices()::putTemplateAsync - , expectWarnings(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)) + assertThat(execute(putTemplate1, client.indices()::putTemplate, client.indices()::putTemplateAsync) .isAcknowledged(), equalTo(true)); org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putTemplate2 = new org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest().name("template-2") .patterns(Arrays.asList("pattern-2", "name-2")) .mapping("custom_doc_type", "name", "type=text") .settings(Settings.builder().put("number_of_shards", "2").put("number_of_replicas", "0")); - assertThat(execute(putTemplate2, client.indices()::putTemplate, client.indices()::putTemplateAsync, - expectWarnings(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)) + assertThat(execute(putTemplate2, client.indices()::putTemplate, client.indices()::putTemplateAsync) .isAcknowledged(), equalTo(true)); org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse getTemplate1 = execute( new GetIndexTemplatesRequest("template-1"), - client.indices()::getTemplate, client.indices()::getTemplateAsync, - expectWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)); + client.indices()::getTemplate, client.indices()::getTemplateAsync); assertThat(getTemplate1.getIndexTemplates(), hasSize(1)); org.elasticsearch.cluster.metadata.IndexTemplateMetaData template1 = getTemplate1.getIndexTemplates().get(0); assertThat(template1.name(), equalTo("template-1")); @@ -1744,16 +1723,14 @@ public void testCRUDIndexTemplateWithTypes() throws Exception { : Arrays.asList("template-*"); GetIndexTemplatesRequest getBothRequest = new GetIndexTemplatesRequest(names); org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse getBoth = execute( - getBothRequest, client.indices()::getTemplate, client.indices()::getTemplateAsync, - expectWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)); + getBothRequest, client.indices()::getTemplate, client.indices()::getTemplateAsync); assertThat(getBoth.getIndexTemplates(), hasSize(2)); assertThat(getBoth.getIndexTemplates().stream().map(org.elasticsearch.cluster.metadata.IndexTemplateMetaData::getName).toArray(), arrayContainingInAnyOrder("template-1", "template-2")); GetIndexTemplatesRequest getAllRequest = new GetIndexTemplatesRequest(); org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse getAll = execute( - getAllRequest, client.indices()::getTemplate, client.indices()::getTemplateAsync, - expectWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)); + getAllRequest, client.indices()::getTemplate, client.indices()::getTemplateAsync); assertThat(getAll.getIndexTemplates().size(), greaterThanOrEqualTo(2)); assertThat(getAll.getIndexTemplates().stream().map(org.elasticsearch.cluster.metadata.IndexTemplateMetaData::getName) .collect(Collectors.toList()), @@ -1767,18 +1744,15 @@ public void testCRUDIndexTemplateWithTypes() throws Exception { client.indices()::deleteTemplate, client.indices()::deleteTemplateAsync)).status(), equalTo(RestStatus.NOT_FOUND)); assertThat(execute(new GetIndexTemplatesRequest("template-*"), - client.indices()::getTemplate, client.indices()::getTemplateAsync, - expectWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)).getIndexTemplates(), hasSize(1)); + client.indices()::getTemplate, client.indices()::getTemplateAsync).getIndexTemplates(), hasSize(1)); assertThat(execute(new GetIndexTemplatesRequest("template-*"), - client.indices()::getTemplate, client.indices()::getTemplateAsync, - expectWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE)).getIndexTemplates() + client.indices()::getTemplate, client.indices()::getTemplateAsync).getIndexTemplates() .get(0).name(), equalTo("template-2")); assertTrue(execute(new DeleteIndexTemplateRequest("template-*"), client.indices()::deleteTemplate, client.indices()::deleteTemplateAsync).isAcknowledged()); assertThat(expectThrows(ElasticsearchException.class, () -> execute(new GetIndexTemplatesRequest("template-*"), - client.indices()::getTemplate, client.indices()::getTemplateAsync, - expectWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE))).status(), equalTo(RestStatus.NOT_FOUND)); + client.indices()::getTemplate, client.indices()::getTemplateAsync)).status(), equalTo(RestStatus.NOT_FOUND)); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java index e5217cf4c6322..4d642ae8ddd26 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java @@ -41,9 +41,9 @@ public class RestCreateIndexAction 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 create index " + - "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 create index 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 RestCreateIndexAction(Settings settings, RestController controller) { super(settings); @@ -58,14 +58,15 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { CreateIndexRequest createIndexRequest = new CreateIndexRequest(request.param("index")); - boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY); + if (request.hasContent()) { Map sourceAsMap = XContentHelper.convertToMap(request.content(), false, request.getXContentType()).v2(); - if (includeTypeName && sourceAsMap.containsKey("mappings")) { + if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER) == false && sourceAsMap.containsKey("mappings")) { deprecationLogger.deprecatedAndMaybeLog("create_index_with_types", TYPES_DEPRECATION_MESSAGE); } + sourceAsMap = prepareMappings(sourceAsMap, includeTypeName); createIndexRequest.source(sourceAsMap, LoggingDeprecationHandler.INSTANCE); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java index 02d9010d0490e..4d00429d4c89c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java @@ -48,9 +48,9 @@ public class RestGetFieldMappingAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestGetFieldMappingAction.class)); - public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] The response format of get field " + - "mapping requests will change in 7.0. Please start using the include_type_name parameter set to false " + - "to move to the new, typeless response format that will become the default."; + static final String TYPES_DEPRECATION_MESSAGE = "[types removal] The parameter include_type_name " + + "should be explicitly specified in get index requests to prepare for 7.0. In 7.0 include_type_name " + + "will default to 'false', which means responses will omit the type name in mapping definitions."; public RestGetFieldMappingAction(Settings settings, RestController controller) { super(settings); @@ -71,11 +71,13 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC final String[] indices = Strings.splitStringByCommaToArray(request.param("index")); final String[] types = request.paramAsStringArrayOrEmptyIfAll("type"); final String[] fields = Strings.splitStringByCommaToArray(request.param("fields")); - final boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY); - if (includeTypeName) { + + if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER) == false) { deprecationLogger.deprecatedAndMaybeLog("get_field_mapping_with_types", TYPES_DEPRECATION_MESSAGE); - } else if (types.length > 0) { + } + + if (includeTypeName == false && types.length > 0) { throw new IllegalArgumentException("Cannot set include_type_name=false and specify types at the same time."); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java index 8c99a18aa4078..40cc7ba438707 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java @@ -51,9 +51,9 @@ public class RestGetIndexTemplateAction extends BaseRestHandler { Collections.singleton(INCLUDE_TYPE_NAME_PARAMETER), Settings.FORMAT_PARAMS)); private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestGetIndexTemplateAction.class)); - public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] The response format of get index " + - "template requests will change in 7.0. Please start using the include_type_name parameter set to false " + - "to move to the new, typeless response format that will become the default."; + static final String TYPES_DEPRECATION_MESSAGE = "[types removal] The parameter include_type_name " + + "should be explicitly specified in get template requests to prepare for 7.0. In 7.0 include_type_name " + + "will default to 'false', which means responses will omit the type name in mapping definitions."; public RestGetIndexTemplateAction(final Settings settings, final RestController controller) { super(settings); @@ -72,7 +72,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC final String[] names = Strings.splitStringByCommaToArray(request.param("name")); final GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(names); - if (request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY)) { + if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER) == false) { deprecationLogger.deprecatedAndMaybeLog("get_index_template_with_types", TYPES_DEPRECATION_MESSAGE); } getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local())); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java index 73435dec46c32..eb7d68f50fa1a 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java @@ -47,9 +47,9 @@ public class RestGetIndicesAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetIndicesAction.class)); - public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] The response format of get indices requests " + - "will change in 7.0. Please start using the include_type_name parameter set to false to move to the new, " + - "typeless response format that will become the default."; + static final String TYPES_DEPRECATION_MESSAGE = "[types removal] The parameter include_type_name " + + "should be explicitly specified in get indices requests to prepare for 7.0. In 7.0 include_type_name " + + "will default to 'false', which means responses will omit the type name in mapping definitions."; private static final Set allowedResponseParameters = Collections .unmodifiableSet(Stream.concat(Collections.singleton(INCLUDE_TYPE_NAME_PARAMETER).stream(), Settings.FORMAT_PARAMS.stream()) @@ -71,7 +71,7 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { String[] indices = Strings.splitStringByCommaToArray(request.param("index")); - if (request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY)) { + if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER) == false) { deprecationLogger.deprecatedAndMaybeLog("get_indices_with_types", TYPES_DEPRECATION_MESSAGE); } final GetIndexRequest getIndexRequest = new GetIndexRequest(); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java index e8b4603bd4fb0..e30d5352104e7 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java @@ -59,9 +59,9 @@ public class RestGetMappingAction extends BaseRestHandler { private static final Logger logger = LogManager.getLogger(RestGetMappingAction.class); private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger); - public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] The response format of get mapping " + - "requests will change in 7.0. Please start using the include_type_name parameter set to false to " + - "move to the new, typeless response format that will become the default."; + static final String TYPES_DEPRECATION_MESSAGE = "[types removal] The parameter include_type_name " + + "should be explicitly specified in get mapping requests to prepare for 7.0. In 7.0 include_type_name " + + "will default to 'false', which means responses will omit the type name in mapping definitions."; public RestGetMappingAction(final Settings settings, final RestController controller) { super(settings); @@ -87,9 +87,11 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC final String[] types = request.paramAsStringArrayOrEmptyIfAll("type"); final boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY); - if (includeTypeName) { + if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER) == false) { deprecationLogger.deprecatedAndMaybeLog("get_mapping_with_types", TYPES_DEPRECATION_MESSAGE); - } else if (types.length > 0) { + } + + if (includeTypeName == false && types.length > 0) { throw new IllegalArgumentException("Types cannot be provided in get mapping requests, unless" + " include_type_name is set to true."); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java index 94f9efb316142..073faeb15c29d 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java @@ -40,9 +40,9 @@ public class RestPutIndexTemplateAction extends BaseRestHandler { private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger( LogManager.getLogger(RestPutIndexTemplateAction.class)); - public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in put index template " + - "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 template 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 RestPutIndexTemplateAction(Settings settings, RestController controller) { super(settings); @@ -69,12 +69,13 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC putRequest.create(request.paramAsBoolean("create", false)); putRequest.cause(request.param("cause", "")); - boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY); Map sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false, request.getXContentType()).v2(); - if (includeTypeName && sourceAsMap.containsKey("mappings")) { + if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER) == false && sourceAsMap.containsKey("mappings")) { DEPRECATION_LOGGER.deprecatedAndMaybeLog("put_index_template_with_types", TYPES_DEPRECATION_MESSAGE); } + + boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY); sourceAsMap = RestCreateIndexAction.prepareMappings(sourceAsMap, includeTypeName); putRequest.source(sourceAsMap); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java index a7e0b3b22d6f2..107febe5dd3b5 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java @@ -35,9 +35,9 @@ public class RestRolloverIndexAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestRolloverIndexAction.class)); - public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] The response format of rollover " + - "index requests will change in 7.0. Please start using the include_type_name parameter set to false " + - "to move to the new, typeless response format that will become the default."; + static final String TYPES_DEPRECATION_MESSAGE = "[types removal] The parameter include_type_name " + + "should be explicitly specified in rollover requests to prepare for 7.0. In 7.0 include_type_name " + + "will default to 'false', which means requests must omit the type name in mapping definitions."; public RestRolloverIndexAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(RestRequest.Method.POST, "/{index}/_rollover", this); @@ -52,7 +52,7 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY); - if (includeTypeName) { + if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER) == false) { deprecationLogger.deprecatedAndMaybeLog("index_rollover_with_types", TYPES_DEPRECATION_MESSAGE); } RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("index"), request.param("new_index")); diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexActionTests.java index 3e14acd801edc..bbafb81b5ca9c 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexActionTests.java @@ -63,7 +63,7 @@ public void testIncludeTypeName() throws IOException { assertWarnings(RestCreateIndexAction.TYPES_DEPRECATION_MESSAGE); Map 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") diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingActionTests.java index e46c295610739..a426d7ecd44a2 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingActionTests.java @@ -49,7 +49,7 @@ public void testIncludeTypeName() { assertWarnings(RestGetFieldMappingAction.TYPES_DEPRECATION_MESSAGE); Map 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.GET) .withPath("some_index/_mapping/field/some_field") diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateActionTests.java new file mode 100644 index 0000000000000..244a2d0cbce7b --- /dev/null +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateActionTests.java @@ -0,0 +1,62 @@ +/* + * 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.admin.indices; + +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.test.rest.FakeRestRequest; +import org.elasticsearch.test.rest.RestActionTestCase; +import org.junit.Before; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER; +import static org.mockito.Mockito.mock; + +public class RestGetIndexTemplateActionTests extends RestActionTestCase { + private RestGetIndexTemplateAction action; + + @Before + public void setUpAction() { + action = new RestGetIndexTemplateAction(Settings.EMPTY, controller()); + } + + public void testIncludeTypeName() throws IOException { + RestRequest deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.GET) + .withPath("/_template/_some_template") + .build(); + action.prepareRequest(deprecatedRequest, mock(NodeClient.class)); + assertWarnings(RestGetIndexTemplateAction.TYPES_DEPRECATION_MESSAGE); + + Map params = new HashMap<>(); + params.put(INCLUDE_TYPE_NAME_PARAMETER, randomFrom("true", "false")); + + RestRequest validRequest = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.GET) + .withPath("/_template/_some_template") + .withParams(params) + .build(); + action.prepareRequest(validRequest, mock(NodeClient.class)); + } +} diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesActionTests.java index c8767a104fd24..11e2b5e9071c6 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesActionTests.java @@ -27,7 +27,6 @@ import org.elasticsearch.test.rest.FakeRestRequest; import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -36,30 +35,24 @@ public class RestGetIndicesActionTests extends ESTestCase { - /** - * Test that setting no "include_type_name" or setting it to "true" raises a warning - */ - public void testIncludeTypeNamesWarning() throws IOException { - Map params = new HashMap<>(); - if (randomBoolean()) { - params.put(INCLUDE_TYPE_NAME_PARAMETER, "true"); - } - RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) + public void testIncludeTypeName() throws IOException { + RestRequest deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry()) .withMethod(RestRequest.Method.GET) .withPath("/some_index") - .withParams(params) .build(); RestGetIndicesAction handler = new RestGetIndicesAction(Settings.EMPTY, mock(RestController.class)); - handler.prepareRequest(request, mock(NodeClient.class)); + handler.prepareRequest(deprecatedRequest, mock(NodeClient.class)); assertWarnings(RestGetIndicesAction.TYPES_DEPRECATION_MESSAGE); - // the same request with the parameter set to "false" should pass without warning - request = new FakeRestRequest.Builder(xContentRegistry()) - .withMethod(RestRequest.Method.GET) - .withParams(Collections.singletonMap(INCLUDE_TYPE_NAME_PARAMETER, "false")) - .withPath("/some_index") - .build(); - handler.prepareRequest(request, mock(NodeClient.class)); + Map params = new HashMap<>(); + params.put(INCLUDE_TYPE_NAME_PARAMETER, randomFrom("true", "false")); + + RestRequest validRequest = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.GET) + .withPath("/some_index") + .withParams(params) + .build(); + handler.prepareRequest(validRequest, mock(NodeClient.class)); } } diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingActionTests.java index 0e044971963c1..885ac4f3a9b89 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingActionTests.java @@ -69,7 +69,7 @@ public void testIncludeTypeName() { assertWarnings(RestGetMappingAction.TYPES_DEPRECATION_MESSAGE); Map 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.GET) .withPath("/some_index/_mappings") diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateActionTests.java index 8f7b26dd1207b..e543868ddba6d 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateActionTests.java @@ -31,7 +31,10 @@ import org.junit.Before; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER; import static org.mockito.Mockito.mock; public class RestPutIndexTemplateActionTests extends RestActionTestCase { @@ -57,12 +60,23 @@ public void testIncludeTypeName() throws IOException { .endObject() .endObject(); - RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) + RestRequest deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry()) .withMethod(RestRequest.Method.PUT) .withPath("/_template/_some_template") .withContent(BytesReference.bytes(typedContent), XContentType.JSON) .build(); - action.prepareRequest(request, mock(NodeClient.class)); + action.prepareRequest(deprecatedRequest, mock(NodeClient.class)); assertWarnings(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE); + + Map params = new HashMap<>(); + params.put(INCLUDE_TYPE_NAME_PARAMETER, randomFrom("true", "false")); + + RestRequest validRequest = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.PUT) + .withPath("/_template/_some_template") + .withParams(params) + .withContent(BytesReference.bytes(typedContent), XContentType.JSON) + .build(); + action.prepareRequest(validRequest, mock(NodeClient.class)); } } diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexActionTests.java new file mode 100644 index 0000000000000..9b86c40ae595b --- /dev/null +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexActionTests.java @@ -0,0 +1,79 @@ +/* + * 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.admin.indices; + +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.test.rest.FakeRestRequest; +import org.elasticsearch.test.rest.RestActionTestCase; +import org.junit.Before; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER; +import static org.mockito.Mockito.mock; + +public class RestRolloverIndexActionTests extends RestActionTestCase { + private RestRolloverIndexAction action; + + @Before + public void setUpAction() { + action = new RestRolloverIndexAction(Settings.EMPTY, controller()); + } + + public void testIncludeTypeName() throws IOException { + XContentBuilder content = XContentFactory.jsonBuilder().startObject() + .startObject("mappings") + .startObject("my_doc") + .startObject("properties") + .startObject("field1").field("type", "keyword").endObject() + .startObject("field2").field("type", "text").endObject() + .endObject() + .endObject() + .endObject() + .endObject(); + + RestRequest deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.PUT) + .withPath("/_rollover/logs") + .withContent(BytesReference.bytes(content), XContentType.JSON) + .build(); + action.prepareRequest(deprecatedRequest, mock(NodeClient.class)); + assertWarnings(RestRolloverIndexAction.TYPES_DEPRECATION_MESSAGE); + + Map params = new HashMap<>(); + params.put(INCLUDE_TYPE_NAME_PARAMETER, randomFrom("true", "false")); + + RestRequest validRequest = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.PUT) + .withPath("/_rollover/logs") + .withParams(params) + .withContent(BytesReference.bytes(content), XContentType.JSON) + .build(); + action.prepareRequest(validRequest, mock(NodeClient.class)); + } +}