Skip to content

Commit

Permalink
Support recovery source new setting in custom index mode (elastic#112654
Browse files Browse the repository at this point in the history
)

This commit fixes the support of the recovery source setting added in elastic#111824 for mappings that use a specific index mode and an explicit _source definition.
  • Loading branch information
jimczi authored Sep 9, 2024
1 parent 6dcca8c commit dd5ac0f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ public SourceFieldMapper build() {
}
if (isDefault()) {
return switch (indexMode) {
case TIME_SERIES -> TSDB_DEFAULT;
case LOGSDB -> LOGSDB_DEFAULT;
default -> DEFAULT;
case TIME_SERIES -> enableRecoverySource ? TSDB_DEFAULT : TSDB_DEFAULT_NO_RECOVERY_SOURCE;
case LOGSDB -> enableRecoverySource ? LOGSDB_DEFAULT : LOGSDB_DEFAULT_NO_RECOVERY_SOURCE;
default -> enableRecoverySource ? DEFAULT : DEFAULT_NO_RECOVERY_SOURCE;
};
}
if (supportsNonDefaultParameterValues == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,28 @@ public void testRecoverySourceWithLogs() throws IOException {
}
}

public void testRecoverySourceWithLogsCustom() throws IOException {
XContentBuilder mappings = topMapping(b -> b.startObject(SourceFieldMapper.NAME).field("mode", "synthetic").endObject());
{
Settings settings = Settings.builder().put(IndexSettings.MODE.getKey(), IndexMode.LOGSDB.getName()).build();
MapperService mapperService = createMapperService(settings, mappings);
DocumentMapper docMapper = mapperService.documentMapper();
ParsedDocument doc = docMapper.parse(source(b -> { b.field("@timestamp", "2012-02-13"); }));
assertNotNull(doc.rootDoc().getField("_recovery_source"));
assertThat(doc.rootDoc().getField("_recovery_source").binaryValue(), equalTo(new BytesRef("{\"@timestamp\":\"2012-02-13\"}")));
}
{
Settings settings = Settings.builder()
.put(IndexSettings.MODE.getKey(), IndexMode.LOGSDB.getName())
.put(INDICES_RECOVERY_SOURCE_ENABLED_SETTING.getKey(), false)
.build();
MapperService mapperService = createMapperService(settings, mappings);
DocumentMapper docMapper = mapperService.documentMapper();
ParsedDocument doc = docMapper.parse(source(b -> b.field("@timestamp", "2012-02-13")));
assertNull(doc.rootDoc().getField("_recovery_source"));
}
}

public void testRecoverySourceWithTimeSeries() throws IOException {
{
Settings settings = Settings.builder()
Expand Down Expand Up @@ -477,4 +499,49 @@ public void testRecoverySourceWithTimeSeries() throws IOException {
assertNull(doc.rootDoc().getField("_recovery_source"));
}
}

public void testRecoverySourceWithTimeSeriesCustom() throws IOException {
String mappings = """
{
"_doc" : {
"_source" : {
"mode" : "synthetic"
},
"properties": {
"field": {
"type": "keyword",
"time_series_dimension": true
}
}
}
}
""";
{
Settings settings = Settings.builder()
.put(IndexSettings.MODE.getKey(), IndexMode.TIME_SERIES.getName())
.put(IndexMetadata.INDEX_ROUTING_PATH.getKey(), "field")
.build();
MapperService mapperService = createMapperService(settings, mappings);
DocumentMapper docMapper = mapperService.documentMapper();
ParsedDocument doc = docMapper.parse(source("123", b -> b.field("@timestamp", "2012-02-13").field("field", "value1"), null));
assertNotNull(doc.rootDoc().getField("_recovery_source"));
assertThat(
doc.rootDoc().getField("_recovery_source").binaryValue(),
equalTo(new BytesRef("{\"@timestamp\":\"2012-02-13\",\"field\":\"value1\"}"))
);
}
{
Settings settings = Settings.builder()
.put(IndexSettings.MODE.getKey(), IndexMode.TIME_SERIES.getName())
.put(IndexMetadata.INDEX_ROUTING_PATH.getKey(), "field")
.put(INDICES_RECOVERY_SOURCE_ENABLED_SETTING.getKey(), false)
.build();
MapperService mapperService = createMapperService(settings, mappings);
DocumentMapper docMapper = mapperService.documentMapper();
ParsedDocument doc = docMapper.parse(
source("123", b -> b.field("@timestamp", "2012-02-13").field("field", randomAlphaOfLength(5)), null)
);
assertNull(doc.rootDoc().getField("_recovery_source"));
}
}
}

0 comments on commit dd5ac0f

Please sign in to comment.