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

Deprecation check for indices with multiple types #36952

Merged
merged 6 commits into from
Jan 10, 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 @@ -26,6 +26,8 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.elasticsearch.index.mapper.MapperService.DEFAULT_MAPPING;

/**
* Index-specific deprecation checks
*/
Expand Down Expand Up @@ -100,12 +102,25 @@ static DeprecationIssue delimitedPayloadFilterCheck(IndexMetaData indexMetaData)

static DeprecationIssue oldIndicesCheck(IndexMetaData indexMetaData) {
Version createdWith = indexMetaData.getCreationVersion();
boolean hasDefaultMapping = indexMetaData.getMappings().containsKey(DEFAULT_MAPPING);
int mappingCount = indexMetaData.getMappings().size();
if (createdWith.before(Version.V_6_0_0)) {
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"Index created before 6.0",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"breaking-changes-7.0.html",
"this index was created using version: " + createdWith);
if ((mappingCount == 2 && !hasDefaultMapping)
|| mappingCount > 2) {
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"Index has more than one mapping type",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html" +
"#_migrating_multi_type_indices_to_single_type",
"This index has more than one mapping type, which is not supported in 7.0. " +
"This index must be reindexed into one or more single-type indices. Mapping types in use: " +
indexMetaData.getMappings().keys());
} else {
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"Index created before 6.0",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"breaking-changes-7.0.html",
"This index was created using version: " + createdWith);
}

}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import java.util.Locale;

import static java.util.Collections.singletonList;
import static org.elasticsearch.index.mapper.MapperService.DEFAULT_MAPPING;
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.INDEX_SETTINGS_CHECKS;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;

public class IndexDeprecationChecksTests extends ESTestCase {

Expand All @@ -36,11 +39,102 @@ public void testOldIndicesCheck() {
"Index created before 6.0",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"breaking-changes-7.0.html",
"this index was created using version: " + createdWith);
"This index was created using version: " + createdWith);
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetaData));
assertEquals(singletonList(expected), issues);
}

public void testMultipleTypesCheckWithDefaultMapping() throws IOException {
String mappingName1 = randomAlphaOfLengthBetween(2, 5);
String mappingJson1 = "{\n" +
" \"properties\": {\n" +
" \"field_a\": {\n" +
" \"type\": \"text\"\n" +
" }\n" +
" }\n" +
"}";
String defaultMappingJson = "{\n" +
" \"properties\": {\n" +
" \"field_b\": {\n" +
" \"type\": \"keyword\"\n" +
" }\n" +
" }\n" +
"}";

Version createdWith = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0,
VersionUtils.getPreviousVersion(Version.V_6_0_0));
IndexMetaData indexMetaData = IndexMetaData.builder("test")
.putMapping(mappingName1, mappingJson1)
.putMapping(DEFAULT_MAPPING, defaultMappingJson)
.settings(settings(createdWith))
.numberOfShards(1)
.numberOfReplicas(0)
.build();

DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"Index created before 6.0",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/" +
"breaking-changes-7.0.html",
"This index was created using version: " + createdWith);
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetaData));
assertEquals(singletonList(expected), issues);
}

public void testMultipleTypesCheck() throws IOException {
String mappingName1 = randomAlphaOfLengthBetween(2, 5);
String mappingJson1 = "{\n" +
" \"properties\": {\n" +
" \"field_a\": {\n" +
" \"type\": \"text\"\n" +
" }\n" +
" }\n" +
"}";
String mappingName2 = randomAlphaOfLengthBetween(6, 10);
String mappingJson2 = "{\n" +
" \"properties\": {\n" +
" \"field_b\": {\n" +
" \"type\": \"keyword\"\n" +
" }\n" +
" }\n" +
"}";

Version createdWith = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0,
VersionUtils.getPreviousVersion(Version.V_6_0_0));
IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.builder("test")
.putMapping(mappingName1, mappingJson1)
.putMapping(mappingName2, mappingJson2)
.settings(settings(createdWith))
.numberOfShards(1)
.numberOfReplicas(0);

if (randomBoolean()) {
String defaultMappingJson = "{\n" +
" \"properties\": {\n" +
" \"field_c\": {\n" +
" \"type\": \"keyword\"\n" +
" }\n" +
" }\n" +
"}";
indexMetaDataBuilder.putMapping(DEFAULT_MAPPING, defaultMappingJson);
}

IndexMetaData indexMetaData = indexMetaDataBuilder.build();
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetaData));
assertEquals(1, issues.size());
DeprecationIssue issue = issues.get(0);
assertEquals("Index has more than one mapping type", issue.getMessage());
assertEquals(DeprecationIssue.Level.CRITICAL, issue.getLevel());
assertEquals(
"https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html" +
"#_migrating_multi_type_indices_to_single_type",
issue.getUrl());
assertThat(issue.getDetails(), allOf(
containsString("This index has more than one mapping type, which is not supported in 7.0. " +
"This index must be reindexed into one or more single-type indices. Mapping types in use: ["),
containsString(mappingName1),
containsString(mappingName2)));
}

public void testDelimitedPayloadFilterCheck() {
Settings settings = settings(
VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, VersionUtils.getPreviousVersion(Version.CURRENT)))
Expand Down