Skip to content

Commit a62228a

Browse files
authored
Allow stored source in logsdb and tsdb (#114454)
1 parent 085ffc3 commit a62228a

File tree

10 files changed

+135
-93
lines changed

10 files changed

+135
-93
lines changed

modules/aggregations/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ dependencies {
4848

4949
tasks.named("yamlRestCompatTestTransform").configure({ task ->
5050
task.skipTest("aggregations/date_agg_per_day_of_week/Date aggregartion per day of week", "week-date behaviour has changed")
51+
task.skipTest("aggregations/time_series/Configure with no synthetic source", "temporary until backport")
5152
})

modules/aggregations/src/yamlRestTest/resources/rest-api-spec/test/aggregations/time_series.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -291,23 +291,6 @@ setup:
291291
sum:
292292
sum:
293293
field: val
294-
---
295-
"Configure with no synthetic source":
296-
- requires:
297-
cluster_features: ["gte_v8.15.0"]
298-
reason: "Error message changed in 8.15.0"
299-
300-
- do:
301-
catch: '/Indices with with index mode \[time_series\] only support synthetic source/'
302-
indices.create:
303-
index: tsdb_error
304-
body:
305-
settings:
306-
mode: time_series
307-
routing_path: [key]
308-
mappings:
309-
_source:
310-
enabled: false
311294

312295
---
313296
"Number for keyword routing field":

modules/data-streams/src/javaRestTest/java/org/elasticsearch/datastreams/logsdb/LogsIndexModeCustomSettingsIT.java

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.elasticsearch.common.settings.Settings;
1616
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1717
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
18-
import org.hamcrest.Matchers;
1918
import org.junit.Before;
2019
import org.junit.ClassRule;
2120

@@ -115,18 +114,62 @@ public void testConfigureStoredSourceBeforeIndexCreation() throws IOException {
115114
}
116115
}""";
117116

117+
assertOK(putComponentTemplate(client, "logs@custom", storedSourceMapping));
118+
assertOK(createDataStream(client, "logs-custom-dev"));
119+
120+
var mapping = getMapping(client, getDataStreamBackingIndex(client, "logs-custom-dev", 0));
121+
String sourceMode = (String) subObject("_source").apply(mapping).get("mode");
122+
assertThat(sourceMode, equalTo("stored"));
123+
}
124+
125+
public void testConfigureDisabledSourceBeforeIndexCreation() {
126+
var storedSourceMapping = """
127+
{
128+
"template": {
129+
"settings": {
130+
"index": {
131+
"mode": "logsdb"
132+
}
133+
},
134+
"mappings": {
135+
"_source": {
136+
"enabled": false
137+
}
138+
}
139+
}
140+
}""";
141+
118142
Exception e = assertThrows(ResponseException.class, () -> putComponentTemplate(client, "logs@custom", storedSourceMapping));
119143
assertThat(
120144
e.getMessage(),
121-
containsString("Failed to parse mapping: Indices with with index mode [logsdb] only support synthetic source")
145+
containsString("Failed to parse mapping: _source can not be disabled in index using [logsdb] index mode")
122146
);
123147
assertThat(e.getMessage(), containsString("mapper_parsing_exception"));
148+
}
124149

125-
assertOK(createDataStream(client, "logs-custom-dev"));
150+
public void testConfigureDisabledSourceModeBeforeIndexCreation() {
151+
var storedSourceMapping = """
152+
{
153+
"template": {
154+
"settings": {
155+
"index": {
156+
"mode": "logsdb"
157+
}
158+
},
159+
"mappings": {
160+
"_source": {
161+
"mode": "disabled"
162+
}
163+
}
164+
}
165+
}""";
126166

127-
var mapping = getMapping(client, getDataStreamBackingIndex(client, "logs-custom-dev", 0));
128-
String sourceMode = (String) subObject("_source").apply(mapping).get("mode");
129-
assertThat(sourceMode, equalTo("synthetic"));
167+
Exception e = assertThrows(ResponseException.class, () -> putComponentTemplate(client, "logs@custom", storedSourceMapping));
168+
assertThat(
169+
e.getMessage(),
170+
containsString("Failed to parse mapping: _source can not be disabled in index using [logsdb] index mode")
171+
);
172+
assertThat(e.getMessage(), containsString("mapper_parsing_exception"));
130173
}
131174

132175
public void testConfigureStoredSourceWhenIndexIsCreated() throws IOException {
@@ -142,8 +185,45 @@ public void testConfigureStoredSourceWhenIndexIsCreated() throws IOException {
142185
}""";
143186

144187
assertOK(putComponentTemplate(client, "logs@custom", storedSourceMapping));
188+
assertOK(createDataStream(client, "logs-custom-dev"));
189+
190+
var mapping = getMapping(client, getDataStreamBackingIndex(client, "logs-custom-dev", 0));
191+
String sourceMode = (String) subObject("_source").apply(mapping).get("mode");
192+
assertThat(sourceMode, equalTo("stored"));
193+
}
194+
195+
public void testConfigureDisabledSourceWhenIndexIsCreated() throws IOException {
196+
var disabledModeMapping = """
197+
{
198+
"template": {
199+
"mappings": {
200+
"_source": {
201+
"enabled": false
202+
}
203+
}
204+
}
205+
}""";
206+
207+
assertOK(putComponentTemplate(client, "logs@custom", disabledModeMapping));
208+
ResponseException e = expectThrows(ResponseException.class, () -> createDataStream(client, "logs-custom-dev"));
209+
assertThat(e.getMessage(), containsString("_source can not be disabled in index using [logsdb] index mode"));
210+
}
211+
212+
public void testConfigureDisabledSourceModeWhenIndexIsCreated() throws IOException {
213+
var disabledModeMapping = """
214+
{
215+
"template": {
216+
"mappings": {
217+
"_source": {
218+
"mode": "disabled"
219+
}
220+
}
221+
}
222+
}""";
223+
224+
assertOK(putComponentTemplate(client, "logs@custom", disabledModeMapping));
145225
ResponseException e = expectThrows(ResponseException.class, () -> createDataStream(client, "logs-custom-dev"));
146-
assertThat(e.getMessage(), containsString("Indices with with index mode [logsdb] only support synthetic source"));
226+
assertThat(e.getMessage(), containsString("_source can not be disabled in index using [logsdb] index mode"));
147227
}
148228

149229
public void testOverrideIndexCodec() throws IOException {
@@ -377,7 +457,7 @@ public void testIgnoreAboveSetting() throws IOException {
377457
);
378458
assertThat(
379459
ex.getMessage(),
380-
Matchers.containsString("Failed to parse value [" + newValue + "] for setting [index.mapping.ignore_above]")
460+
containsString("Failed to parse value [" + newValue + "] for setting [index.mapping.ignore_above]")
381461
);
382462
}
383463
}

rest-api-spec/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,8 @@ tasks.named("precommit").configure {
5757
tasks.named("yamlRestCompatTestTransform").configure({task ->
5858
task.skipTest("indices.sort/10_basic/Index Sort", "warning does not exist for compatibility")
5959
task.skipTest("search/330_fetch_fields/Test search rewrite", "warning does not exist for compatibility")
60+
task.skipTest("tsdb/20_mapping/disabled source", "temporary until backported")
61+
task.skipTest("logsdb/20_source_mapping/disabled _source is not supported", "temporary until backported")
62+
task.skipTest("tsdb/20_mapping/regular source", "temporary until backported")
63+
task.skipTest("logsdb/20_source_mapping/stored _source mode is not supported", "temporary until backported")
6064
})
Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
---
2-
stored _source mode is not supported:
2+
stored _source mode is supported:
33
- requires:
4-
test_runner_features: [capabilities]
5-
capabilities:
6-
- method: PUT
7-
path: /{index}
8-
capabilities: [logsdb_index_mode]
9-
reason: "Support for 'logsdb' index mode capability required"
10-
11-
- skip:
12-
known_issues:
13-
- cluster_feature: "gte_v8.15.0"
14-
fixed_by: "gte_v8.16.0"
15-
reason: "Development of logs index mode spans 8.15 and 8.16"
4+
cluster_features: ["mapper.source.remove_synthetic_source_only_validation"]
5+
reason: requires new validation logic
166

177
- do:
18-
catch: bad_request
198
indices.create:
209
index: test-stored-source
2110
body:
@@ -25,31 +14,17 @@ stored _source mode is not supported:
2514
mappings:
2615
_source:
2716
mode: stored
28-
properties:
29-
"@timestamp":
30-
type: date
31-
host.name:
32-
type: keyword
17+
- do:
18+
indices.get:
19+
index: test-stored-source
3320

34-
- match: { error.type: "mapper_parsing_exception" }
35-
- match: { error.root_cause.0.type: "mapper_parsing_exception" }
36-
- match: { error.reason: "Failed to parse mapping: Indices with with index mode [logsdb] only support synthetic source" }
21+
- match: { test-stored-source.mappings._source.mode: "stored" }
3722

3823
---
3924
disabled _source is not supported:
4025
- requires:
41-
test_runner_features: [capabilities]
42-
capabilities:
43-
- method: PUT
44-
path: /{index}
45-
capabilities: [logsdb_index_mode]
46-
reason: "Support for 'logsdb' index mode capability required"
47-
48-
- skip:
49-
known_issues:
50-
- cluster_feature: "gte_v8.15.0"
51-
fixed_by: "gte_v8.16.0"
52-
reason: "Development of logs index mode spans 8.15 and 8.16"
26+
cluster_features: ["mapper.source.remove_synthetic_source_only_validation"]
27+
reason: requires new error message
5328

5429
- do:
5530
catch: bad_request
@@ -62,33 +37,23 @@ disabled _source is not supported:
6237
mappings:
6338
_source:
6439
enabled: false
65-
properties:
66-
"@timestamp":
67-
type: date
68-
host.name:
69-
type: keyword
7040

7141
- match: { error.type: "mapper_parsing_exception" }
7242
- match: { error.root_cause.0.type: "mapper_parsing_exception" }
73-
- match: { error.reason: "Failed to parse mapping: Indices with with index mode [logsdb] only support synthetic source" }
43+
- match: { error.reason: "Failed to parse mapping: _source can not be disabled in index using [logsdb] index mode" }
7444

7545
- do:
7646
catch: bad_request
7747
indices.create:
78-
index: test-disabled-source
48+
index: test-disabled-mode-source
7949
body:
8050
settings:
8151
index:
8252
mode: logsdb
8353
mappings:
8454
_source:
8555
mode: disabled
86-
properties:
87-
"@timestamp":
88-
type: date
89-
host.name:
90-
type: keyword
9156

9257
- match: { error.type: "mapper_parsing_exception" }
9358
- match: { error.root_cause.0.type: "mapper_parsing_exception" }
94-
- match: { error.reason: "Failed to parse mapping: Indices with with index mode [logsdb] only support synthetic source" }
59+
- match: { error.reason: "Failed to parse mapping: _source can not be disabled in index using [logsdb] index mode" }

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/tsdb/20_mapping.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,12 @@ nested fields:
456456
- match: {tsdb-synthetic.mappings._source.mode: synthetic}
457457

458458
---
459-
regular source:
459+
stored source is supported:
460460
- requires:
461-
cluster_features: ["gte_v8.7.0"]
462-
reason: synthetic source
461+
cluster_features: ["mapper.source.remove_synthetic_source_only_validation"]
462+
reason: requires new validation logic
463463

464464
- do:
465-
catch: '/time series indices only support synthetic source/'
466465
indices.create:
467466
index: tsdb_index
468467
body:
@@ -486,14 +485,21 @@ regular source:
486485
uid:
487486
type: keyword
488487
time_series_dimension: true
488+
489+
- do:
490+
indices.get:
491+
index: tsdb_index
492+
493+
- match: { tsdb_index.mappings._source.mode: "stored" }
494+
489495
---
490-
disabled source:
496+
disabled source is not supported:
491497
- requires:
492-
cluster_features: ["gte_v8.7.0"]
493-
reason: synthetic source
498+
cluster_features: ["mapper.source.remove_synthetic_source_only_validation"]
499+
reason: requires new error message
494500

495501
- do:
496-
catch: '/time series indices only support synthetic source/'
502+
catch: bad_request
497503
indices.create:
498504
index: tsdb_index
499505
body:
@@ -518,6 +524,10 @@ disabled source:
518524
type: keyword
519525
time_series_dimension: true
520526

527+
- match: { error.type: "mapper_parsing_exception" }
528+
- match: { error.root_cause.0.type: "mapper_parsing_exception" }
529+
- match: { error.reason: "Failed to parse mapping: _source can not be disabled in index using [time_series] index mode" }
530+
521531
---
522532
source include/exclude:
523533
- requires:

server/src/main/java/org/elasticsearch/index/IndexMode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ public boolean shouldValidateTimestamp() {
217217

218218
@Override
219219
public void validateSourceFieldMapper(SourceFieldMapper sourceFieldMapper) {
220-
if (sourceFieldMapper.isSynthetic() == false) {
221-
throw new IllegalArgumentException("time series indices only support synthetic source");
220+
if (sourceFieldMapper.enabled() == false) {
221+
throw new IllegalArgumentException("_source can not be disabled in index using [" + IndexMode.TIME_SERIES + "] index mode");
222222
}
223223
}
224224

@@ -292,8 +292,8 @@ public boolean shouldValidateTimestamp() {
292292

293293
@Override
294294
public void validateSourceFieldMapper(SourceFieldMapper sourceFieldMapper) {
295-
if (sourceFieldMapper.isSynthetic() == false) {
296-
throw new IllegalArgumentException("Indices with with index mode [" + IndexMode.LOGSDB + "] only support synthetic source");
295+
if (sourceFieldMapper.enabled() == false) {
296+
throw new IllegalArgumentException("_source can not be disabled in index using [" + IndexMode.LOGSDB + "] index mode");
297297
}
298298
}
299299

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public Set<NodeFeature> getFeatures() {
5858

5959
@Override
6060
public Set<NodeFeature> getTestFeatures() {
61-
return Set.of(RangeFieldMapper.DATE_RANGE_INDEXING_FIX, IgnoredSourceFieldMapper.DONT_EXPAND_DOTS_IN_IGNORED_SOURCE);
61+
return Set.of(
62+
RangeFieldMapper.DATE_RANGE_INDEXING_FIX,
63+
IgnoredSourceFieldMapper.DONT_EXPAND_DOTS_IN_IGNORED_SOURCE,
64+
SourceFieldMapper.REMOVE_SYNTHETIC_SOURCE_ONLY_VALIDATION
65+
);
6266
}
6367
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.common.compress.CompressedXContent;
1313
import org.elasticsearch.common.xcontent.XContentHelper;
1414
import org.elasticsearch.core.Nullable;
15-
import org.elasticsearch.index.IndexMode;
1615
import org.elasticsearch.index.mapper.MapperService.MergeReason;
1716
import org.elasticsearch.xcontent.XContentType;
1817

@@ -147,10 +146,6 @@ Mapping parse(@Nullable String type, MergeReason reason, Map<String, Object> map
147146
assert fieldNodeMap.isEmpty();
148147

149148
if (metadataFieldMapper instanceof SourceFieldMapper sfm) {
150-
// Validation in other places should have failed first
151-
assert sfm.isSynthetic()
152-
|| (sfm.isSynthetic() == false && mappingParserContext.getIndexSettings().getMode() != IndexMode.TIME_SERIES)
153-
: "synthetic source can't be disabled in a time series index";
154149
isSourceSynthetic = sfm.isSynthetic();
155150
}
156151

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public class SourceFieldMapper extends MetadataFieldMapper {
5151
public static final NodeFeature SYNTHETIC_SOURCE_COPY_TO_INSIDE_OBJECTS_FIX = new NodeFeature(
5252
"mapper.source.synthetic_source_copy_to_inside_objects_fix"
5353
);
54+
public static final NodeFeature REMOVE_SYNTHETIC_SOURCE_ONLY_VALIDATION = new NodeFeature(
55+
"mapper.source.remove_synthetic_source_only_validation"
56+
);
5457

5558
public static final String NAME = "_source";
5659
public static final String RECOVERY_SOURCE_NAME = "_recovery_source";
@@ -235,9 +238,6 @@ private boolean isDefault() {
235238
@Override
236239
public SourceFieldMapper build() {
237240
if (enabled.getValue().explicit()) {
238-
if (indexMode != null && indexMode.isSyntheticSourceEnabled()) {
239-
throw new MapperParsingException("Indices with with index mode [" + indexMode + "] only support synthetic source");
240-
}
241241
if (mode.get() != null) {
242242
throw new MapperParsingException("Cannot set both [mode] and [enabled] parameters");
243243
}

0 commit comments

Comments
 (0)