Skip to content

Commit

Permalink
Automatically adjust ignore_malformed only for the @timestamp (#109948)
Browse files Browse the repository at this point in the history
We introduced automatic disabling ignore_malformed for the @timestamp field with #99346, but the change
was applied to any field with name @timestamp under any path, while it should have been applied
only to the top-level @timestamp field.

Relates to #107760
  • Loading branch information
javanna committed Jul 1, 2024
1 parent c89ee3b commit 42564fc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog/109948.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 109948
summary: Automatically adjust `ignore_malformed` only for the @timestamp
area: Mapping
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,29 @@ public void testValidateDefaultIgnoreMalformed() throws Exception {
b.startObject("@timestamp");
b.field("type", "date");
b.endObject();
b.startObject("summary");
{
b.startObject("properties");
{
b.startObject("@timestamp");
b.field("type", "date");
b.endObject();
}
b.endObject();
}
b.endObject();
})
);
assertThat(mapperService, notNullValue());
assertThat(mapperService.documentMapper().mappers().getMapper("@timestamp"), notNullValue());
assertThat(((DateFieldMapper) mapperService.documentMapper().mappers().getMapper("@timestamp")).ignoreMalformed(), is(false));
DateFieldMapper summaryTimestamp = (DateFieldMapper) (mapperService.documentMapper()
.mappers()
.objectMappers()
.get("summary")
.getMapper("@timestamp"));
assertThat(summaryTimestamp, notNullValue());
assertThat(summaryTimestamp.ignoreMalformed(), is(true));
}
{
MapperService mapperService = createMapperService(
Expand All @@ -193,11 +211,22 @@ public void testValidateDefaultIgnoreMalformed() throws Exception {
b.field("type", "date");
b.field("ignore_malformed", false);
b.endObject();
b.startObject("summary.@timestamp");
b.field("type", "date");
b.field("ignore_malformed", false);
b.endObject();
})
);
assertThat(mapperService, notNullValue());
assertThat(mapperService.documentMapper().mappers().getMapper("@timestamp"), notNullValue());
assertThat(((DateFieldMapper) mapperService.documentMapper().mappers().getMapper("@timestamp")).ignoreMalformed(), is(false));
DateFieldMapper summaryTimestamp = (DateFieldMapper) (mapperService.documentMapper()
.mappers()
.objectMappers()
.get("summary")
.getMapper("@timestamp"));
assertThat(summaryTimestamp, notNullValue());
assertThat(summaryTimestamp.ignoreMalformed(), is(false));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public DateFieldMapper build(MapperBuilderContext context) {
);

Long nullTimestamp = parseNullValue(ft);
if (leafName().equals(DataStreamTimestampFieldMapper.DEFAULT_PATH)
if (ft.name().equals(DataStreamTimestampFieldMapper.DEFAULT_PATH)
&& context.isDataStream()
&& ignoreMalformed.isConfigured() == false) {
ignoreMalformed.setValue(false);
Expand Down

0 comments on commit 42564fc

Please sign in to comment.