Skip to content

Commit 68de9a1

Browse files
authored
Automatically adjust ignore_malformed only for the @timestamp (#109948)
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
1 parent 00c9943 commit 68de9a1

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

docs/changelog/109948.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 109948
2+
summary: Automatically adjust `ignore_malformed` only for the @timestamp
3+
area: Mapping
4+
type: bug
5+
issues: []

modules/data-streams/src/test/java/org/elasticsearch/datastreams/mapper/DataStreamTimestampFieldMapperTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,29 @@ public void testValidateDefaultIgnoreMalformed() throws Exception {
177177
b.startObject("@timestamp");
178178
b.field("type", "date");
179179
b.endObject();
180+
b.startObject("summary");
181+
{
182+
b.startObject("properties");
183+
{
184+
b.startObject("@timestamp");
185+
b.field("type", "date");
186+
b.endObject();
187+
}
188+
b.endObject();
189+
}
190+
b.endObject();
180191
})
181192
);
182193
assertThat(mapperService, notNullValue());
183194
assertThat(mapperService.documentMapper().mappers().getMapper("@timestamp"), notNullValue());
184195
assertThat(((DateFieldMapper) mapperService.documentMapper().mappers().getMapper("@timestamp")).ignoreMalformed(), is(false));
196+
DateFieldMapper summaryTimestamp = (DateFieldMapper) (mapperService.documentMapper()
197+
.mappers()
198+
.objectMappers()
199+
.get("summary")
200+
.getMapper("@timestamp"));
201+
assertThat(summaryTimestamp, notNullValue());
202+
assertThat(summaryTimestamp.ignoreMalformed(), is(true));
185203
}
186204
{
187205
MapperService mapperService = createMapperService(
@@ -193,11 +211,22 @@ public void testValidateDefaultIgnoreMalformed() throws Exception {
193211
b.field("type", "date");
194212
b.field("ignore_malformed", false);
195213
b.endObject();
214+
b.startObject("summary.@timestamp");
215+
b.field("type", "date");
216+
b.field("ignore_malformed", false);
217+
b.endObject();
196218
})
197219
);
198220
assertThat(mapperService, notNullValue());
199221
assertThat(mapperService.documentMapper().mappers().getMapper("@timestamp"), notNullValue());
200222
assertThat(((DateFieldMapper) mapperService.documentMapper().mappers().getMapper("@timestamp")).ignoreMalformed(), is(false));
223+
DateFieldMapper summaryTimestamp = (DateFieldMapper) (mapperService.documentMapper()
224+
.mappers()
225+
.objectMappers()
226+
.get("summary")
227+
.getMapper("@timestamp"));
228+
assertThat(summaryTimestamp, notNullValue());
229+
assertThat(summaryTimestamp.ignoreMalformed(), is(false));
201230
}
202231
}
203232
}

server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public DateFieldMapper build(MapperBuilderContext context) {
359359
);
360360

361361
Long nullTimestamp = parseNullValue(ft);
362-
if (name().equals(DataStreamTimestampFieldMapper.DEFAULT_PATH)
362+
if (ft.name().equals(DataStreamTimestampFieldMapper.DEFAULT_PATH)
363363
&& context.isDataStream()
364364
&& ignoreMalformed.isConfigured() == false) {
365365
ignoreMalformed.setValue(false);

0 commit comments

Comments
 (0)