Skip to content

Commit 22d00ed

Browse files
committed
Update the docs and deprecation info API.
1 parent d86f83e commit 22d00ed

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

docs/reference/migration/migrate_7_2.asciidoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,16 @@ In earlier versions you could include a range of ports in entries in the
2929
unexpectedly ignored the rest. For instance if you set `discovery.seed_hosts:
3030
"10.11.12.13:9300-9310"` then {es} would only use `10.11.12.13:9300` for
3131
discovery. Seed host addresses containing port ranges are now rejected.
32+
33+
[[breaking_72_mapping_changes]]
34+
=== Mapping changes
35+
36+
[float]
37+
==== Defining multi-fields within multi-fields
38+
39+
Previously, it was possible to define a multi-field within a multi-field.
40+
Defining chained multi-fields is now deprecated and will no longer be supported
41+
in 8.0. To resolve the issue, all instances of `fields` that occur within a
42+
`fields` block should be removed from the mappings, either by flattening the
43+
chained `fields` blocks into a single level, or by switching to `copy_to` if
44+
appropriate.

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ private DeprecationChecks() {
4747
static List<Function<IndexMetaData, DeprecationIssue>> INDEX_SETTINGS_CHECKS =
4848
Collections.unmodifiableList(Arrays.asList(
4949
IndexDeprecationChecks::oldIndicesCheck,
50-
IndexDeprecationChecks::tooManyFieldsCheck
50+
IndexDeprecationChecks::tooManyFieldsCheck,
51+
IndexDeprecationChecks::chainedMultiFieldsCheck
5152
));
5253

5354
static List<BiFunction<DatafeedConfig, NamedXContentRegistry, DeprecationIssue>> ML_SETTINGS_CHECKS =

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,32 @@ static DeprecationIssue tooManyFieldsCheck(IndexMetaData indexMetaData) {
115115
return null;
116116
}
117117

118+
static DeprecationIssue chainedMultiFieldsCheck(IndexMetaData indexMetaData) {
119+
List<String> issues = new ArrayList<>();
120+
fieldLevelMappingIssue(indexMetaData, ((mappingMetaData, sourceAsMap) -> issues.addAll(
121+
findInPropertiesRecursively(mappingMetaData.type(), sourceAsMap, IndexDeprecationChecks::containsChainedMultiFields))));
122+
if (issues.size() > 0) {
123+
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
124+
"Multi-fields within multi-fields",
125+
"https://www.elastic.co/guide/en/elasticsearch/reference/7.2/breaking-changes-7.2.html" +
126+
"#_defining_multi_fields_within_multi_fields",
127+
"The names of fields that contain chained multi-fields: " + issues.toString());
128+
}
129+
return null;
130+
}
131+
132+
private static boolean containsChainedMultiFields(Map<?, ?> property) {
133+
if (property.containsKey("fields")) {
134+
Map<?, ?> fields = (Map<?, ?>) property.get("fields");
135+
for (Object rawSubField: fields.values()) {
136+
Map<?, ?> subField = (Map<?, ?>) rawSubField;
137+
if (subField.containsKey("fields")) {
138+
return true;
139+
}
140+
}
141+
}
142+
return false;
143+
}
118144

119145
private static final Set<String> TYPES_THAT_DONT_COUNT;
120146
static {

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import org.elasticsearch.Version;
1010
import org.elasticsearch.cluster.metadata.IndexMetaData;
1111
import org.elasticsearch.common.Strings;
12+
import org.elasticsearch.common.bytes.BytesReference;
1213
import org.elasticsearch.common.xcontent.XContentBuilder;
14+
import org.elasticsearch.common.xcontent.XContentFactory;
1315
import org.elasticsearch.index.IndexSettings;
1416
import org.elasticsearch.test.ESTestCase;
1517
import org.elasticsearch.test.VersionUtils;
@@ -110,6 +112,43 @@ public void testTooManyFieldsCheck() throws IOException {
110112
assertEquals(0, withDefaultFieldIssues.size());
111113
}
112114

115+
public void testChainedMultiFields() throws IOException {
116+
XContentBuilder xContent = XContentFactory.jsonBuilder().startObject()
117+
.startObject("properties")
118+
.startObject("field")
119+
.field("type", "keyword")
120+
.startObject("fields")
121+
.startObject("sub-field")
122+
.field("type", "keyword")
123+
.startObject("fields")
124+
.startObject("sub-sub-field")
125+
.field("type", "keyword")
126+
.endObject()
127+
.endObject()
128+
.endObject()
129+
.endObject()
130+
.endObject()
131+
.endObject()
132+
.endObject();
133+
String mapping = BytesReference.bytes(xContent).utf8ToString();
134+
135+
IndexMetaData simpleIndex = IndexMetaData.builder(randomAlphaOfLengthBetween(5, 10))
136+
.settings(settings(Version.V_7_2_0))
137+
.numberOfShards(1)
138+
.numberOfReplicas(1)
139+
.putMapping("_doc", mapping)
140+
.build();
141+
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(simpleIndex));
142+
assertEquals(1, issues.size());
143+
144+
DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
145+
"Multi-fields within multi-fields",
146+
"https://www.elastic.co/guide/en/elasticsearch/reference/7.2/breaking-changes-7.2.html" +
147+
"#_defining_multi_fields_within_multi_fields",
148+
"The names of fields that contain chained multi-fields: [[type: _doc, field: field]]");
149+
assertEquals(singletonList(expected), issues);
150+
}
151+
113152
static void addRandomFields(final int fieldLimit,
114153
XContentBuilder mappingBuilder) throws IOException {
115154
AtomicInteger fieldCount = new AtomicInteger(0);

0 commit comments

Comments
 (0)