Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only issue a deprecation warning if include_type_name is not set. #38825

Merged
merged 1 commit into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String, Object> getIndexResponse = getAsMap(indexName);
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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<String, Object> getIndexResponse = getAsMap(indexName);
Expand Down Expand Up @@ -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<String, Object> mappings = getMappingsResponse.getMappings().get(indexName).get("_doc").sourceAsMap();
Map<String, String> type = new HashMap<>();
Expand Down Expand Up @@ -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<String, org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetaData>
fieldMappingMap = getFieldMappingsResponse.mappings().get(indexName).get("_doc");
Expand Down Expand Up @@ -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<String, Boolean> conditionStatus = rolloverResponse.getConditionStatus();
Expand Down Expand Up @@ -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<String, Object> templates = getAsMap("/_template/my-template");
Expand Down Expand Up @@ -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<String, Object> templates = getAsMap("/_template/my-template");
Expand Down Expand Up @@ -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"));
Expand All @@ -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()),
Expand All @@ -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));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<String, Object> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get index requests
@jtibshirani should it be "get field mapping requests"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mayya-sharipova, will fix. I somehow make this mistake every time...

"will default to 'false', which means responses will omit the type name in mapping definitions.";

public RestGetFieldMappingAction(Settings settings, RestController controller) {
super(settings);
Expand All @@ -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.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> allowedResponseParameters = Collections
.unmodifiableSet(Stream.concat(Collections.singleton(INCLUDE_TYPE_NAME_PARAMETER).stream(), Settings.FORMAT_PARAMS.stream())
Expand All @@ -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();
Expand Down
Loading