|
6 | 6 | */
|
7 | 7 | package org.elasticsearch.xpack.datastreams.mapper;
|
8 | 8 |
|
| 9 | +import org.elasticsearch.Version; |
9 | 10 | import org.elasticsearch.common.CheckedConsumer;
|
| 11 | +import org.elasticsearch.common.settings.Settings; |
10 | 12 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
| 13 | +import org.elasticsearch.index.mapper.DateFieldMapper; |
11 | 14 | import org.elasticsearch.index.mapper.DocumentMapper;
|
| 15 | +import org.elasticsearch.index.mapper.FieldMapper; |
12 | 16 | import org.elasticsearch.index.mapper.MapperException;
|
| 17 | +import org.elasticsearch.index.mapper.MapperService; |
13 | 18 | import org.elasticsearch.index.mapper.MetadataMapperTestCase;
|
14 | 19 | import org.elasticsearch.index.mapper.ParsedDocument;
|
15 | 20 | import org.elasticsearch.plugins.Plugin;
|
|
20 | 25 | import java.util.List;
|
21 | 26 |
|
22 | 27 | import static org.hamcrest.Matchers.equalTo;
|
| 28 | +import static org.hamcrest.Matchers.is; |
| 29 | +import static org.hamcrest.Matchers.notNullValue; |
23 | 30 |
|
24 | 31 | public class DataStreamTimestampFieldMapperTests extends MetadataMapperTestCase {
|
25 | 32 |
|
@@ -145,4 +152,30 @@ public void testValidateNotDisallowedAttribute() {
|
145 | 152 | })));
|
146 | 153 | assertThat(e.getMessage(), equalTo("data stream timestamp field [@timestamp] has disallowed attributes: [store]"));
|
147 | 154 | }
|
| 155 | + |
| 156 | + public void testValidateDefaultIgnoreMalformed() throws Exception { |
| 157 | + Settings indexSettings = Settings.builder().put(FieldMapper.IGNORE_MALFORMED_SETTING.getKey(), true).build(); |
| 158 | + Exception e = expectThrows( |
| 159 | + IllegalArgumentException.class, |
| 160 | + () -> createMapperService(Version.CURRENT, indexSettings, () -> true, timestampMapping(true, b -> { |
| 161 | + b.startObject("@timestamp"); |
| 162 | + b.field("type", "date"); |
| 163 | + b.endObject(); |
| 164 | + })) |
| 165 | + ); |
| 166 | + assertThat( |
| 167 | + e.getMessage(), |
| 168 | + equalTo("data stream timestamp field [@timestamp] has disallowed [ignore_malformed] attribute specified") |
| 169 | + ); |
| 170 | + |
| 171 | + MapperService mapperService = createMapperService(Version.CURRENT, indexSettings, () -> true, timestampMapping(true, b -> { |
| 172 | + b.startObject("@timestamp"); |
| 173 | + b.field("type", "date"); |
| 174 | + b.field("ignore_malformed", false); |
| 175 | + b.endObject(); |
| 176 | + })); |
| 177 | + assertThat(mapperService, notNullValue()); |
| 178 | + assertThat(mapperService.documentMapper().mappers().getMapper("@timestamp"), notNullValue()); |
| 179 | + assertThat(((DateFieldMapper) mapperService.documentMapper().mappers().getMapper("@timestamp")).getIgnoreMalformed(), is(false)); |
| 180 | + } |
148 | 181 | }
|
0 commit comments