Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}
}
}