-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Deprecate support for chained multi-fields. #42330
Changes from 1 commit
d86f83e
22d00ed
7fb498e
d83200c
afc2ca4
25eecd8
a5e6dfa
8380cb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,32 @@ static DeprecationIssue tooManyFieldsCheck(IndexMetaData indexMetaData) { | |
return null; | ||
} | ||
|
||
static DeprecationIssue chainedMultiFieldsCheck(IndexMetaData indexMetaData) { | ||
List<String> issues = new ArrayList<>(); | ||
fieldLevelMappingIssue(indexMetaData, ((mappingMetaData, sourceAsMap) -> issues.addAll( | ||
findInPropertiesRecursively(mappingMetaData.type(), sourceAsMap, IndexDeprecationChecks::containsChainedMultiFields)))); | ||
if (issues.size() > 0) { | ||
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, | ||
"Multi-fields within multi-fields", | ||
"https://www.elastic.co/guide/en/elasticsearch/reference/7.2/breaking-changes-7.2.html" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Historically, we've usually linked to the next major version breaking changes list (8.0 in this case), but this also has a few issues: Until the 8.0 branch is cut, the only way to link to these docs is by using While having this in the breaking changes list for 7.2 and linking to it there would resolve this problem, I don't think it's how we've typically organized the breaking changes list, and might cause issues keeping up to date if we change the deprecation plan. Basically there's a bunch of problems with how the breaking changes lists and links to them have work at the moment and there's no good options, all I'm pointing out here is that this is different from what we usually do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you suggest I change this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think that's what I would recommend for now, that way if we make a change to the docs to make the situation better it'll be easier to do all at once. |
||
"#_defining_multi_fields_within_multi_fields", | ||
"The names of fields that contain chained multi-fields: " + issues.toString()); | ||
} | ||
return null; | ||
} | ||
|
||
private static boolean containsChainedMultiFields(Map<?, ?> property) { | ||
if (property.containsKey("fields")) { | ||
Map<?, ?> fields = (Map<?, ?>) property.get("fields"); | ||
for (Object rawSubField: fields.values()) { | ||
Map<?, ?> subField = (Map<?, ?>) rawSubField; | ||
if (subField.containsKey("fields")) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private static final Set<String> TYPES_THAT_DONT_COUNT; | ||
static { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,9 @@ | |
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentFactory; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.VersionUtils; | ||
|
@@ -110,6 +112,43 @@ public void testTooManyFieldsCheck() throws IOException { | |
assertEquals(0, withDefaultFieldIssues.size()); | ||
} | ||
|
||
public void testChainedMultiFields() throws IOException { | ||
XContentBuilder xContent = XContentFactory.jsonBuilder().startObject() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like this test case to include at least one field that has a non-chained multi-field to verify that the warning message only contains the fields with a problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
.startObject("properties") | ||
.startObject("field") | ||
.field("type", "keyword") | ||
.startObject("fields") | ||
.startObject("sub-field") | ||
.field("type", "keyword") | ||
.startObject("fields") | ||
.startObject("sub-sub-field") | ||
.field("type", "keyword") | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject(); | ||
String mapping = BytesReference.bytes(xContent).utf8ToString(); | ||
|
||
IndexMetaData simpleIndex = IndexMetaData.builder(randomAlphaOfLengthBetween(5, 10)) | ||
.settings(settings(Version.V_7_2_0)) | ||
.numberOfShards(1) | ||
.numberOfReplicas(1) | ||
.putMapping("_doc", mapping) | ||
.build(); | ||
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(simpleIndex)); | ||
assertEquals(1, issues.size()); | ||
|
||
DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.CRITICAL, | ||
"Multi-fields within multi-fields", | ||
"https://www.elastic.co/guide/en/elasticsearch/reference/7.2/breaking-changes-7.2.html" + | ||
"#_defining_multi_fields_within_multi_fields", | ||
"The names of fields that contain chained multi-fields: [[type: _doc, field: field]]"); | ||
assertEquals(singletonList(expected), issues); | ||
} | ||
|
||
static void addRandomFields(final int fieldLimit, | ||
XContentBuilder mappingBuilder) throws IOException { | ||
AtomicInteger fieldCount = new AtomicInteger(0); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will 8.0 fail to open an index which has chained multi-fields that was created in 7.x? Usually we support all indices created in ($MAJOR-1), even if they use deprecated features.
If 8.0 will be able to open indices created in 7.x that have chained multi-fields, this should be
Level.WARNING
rather thanLevel.CRITICAL
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out, I will make sure to update the 8.0 PR to still allow chained multi-fields on indices created prior to 8.0. With that change, I'll also be able to lower this to
Level.WARNING
.