Skip to content

Commit

Permalink
Handle index.mapping.ignore_malformed in downsampling (#119134)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkts authored Dec 23, 2024
1 parent 21fe5a9 commit c16bcb6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/119134.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 119134
summary: Handle `index.mapping.ignore_malformed` in downsampling
area: Downsampling
type: bug
issues:
- 119075
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.TimeSeriesParams;
Expand Down Expand Up @@ -723,6 +724,9 @@ private static void addTimestampField(
if (mapping.get("format") != null) {
builder.field("format", mapping.get("format"));
}
if (mapping.get("ignore_malformed") != null) {
builder.field("ignore_malformed", mapping.get("ignore_malformed"));
}
}
} catch (IOException e) {
throw new ElasticsearchException("Unable to create timestamp field mapping for field [" + timestampField + "]", e);
Expand Down Expand Up @@ -897,6 +901,12 @@ private void createDownsampleIndex(
sourceIndexMetadata.getSettings().get(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey())
);
}
if (sourceIndexMetadata.getSettings().hasValue(FieldMapper.IGNORE_MALFORMED_SETTING.getKey())) {
builder.put(
FieldMapper.IGNORE_MALFORMED_SETTING.getKey(),
sourceIndexMetadata.getSettings().get(FieldMapper.IGNORE_MALFORMED_SETTING.getKey())
);
}

CreateIndexClusterStateUpdateRequest createIndexClusterStateUpdateRequest = new CreateIndexClusterStateUpdateRequest(
"downsample",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.engine.VersionConflictEngineException;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.TimeSeriesIdFieldMapper;
import org.elasticsearch.index.mapper.TimeSeriesParams;
Expand Down Expand Up @@ -201,14 +202,19 @@ public void setup() throws IOException {
IndexSettings.TIME_SERIES_START_TIME.getKey(),
DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.formatMillis(Instant.ofEpochMilli(startTime).toEpochMilli())
)
.put(IndexSettings.TIME_SERIES_END_TIME.getKey(), "2106-01-08T23:40:53.384Z");
.put(IndexSettings.TIME_SERIES_END_TIME.getKey(), "2106-01-08T23:40:53.384Z")
.put(FieldMapper.IGNORE_MALFORMED_SETTING.getKey(), randomBoolean());

if (randomBoolean()) {
settings.put(IndexMetadata.SETTING_INDEX_HIDDEN, randomBoolean());
}

XContentBuilder mapping = jsonBuilder().startObject().startObject("_doc").startObject("properties");
mapping.startObject(FIELD_TIMESTAMP).field("type", "date").endObject();
mapping.startObject(FIELD_TIMESTAMP).field("type", "date");
if (settings.get(FieldMapper.IGNORE_MALFORMED_SETTING.getKey()).equals("true")) {
mapping.field("ignore_malformed", false);
}
mapping.endObject();

// Dimensions
mapping.startObject(FIELD_DIMENSION_1).field("type", "keyword").field("time_series_dimension", true).endObject();
Expand Down

0 comments on commit c16bcb6

Please sign in to comment.