Skip to content

Commit bfdde9b

Browse files
authored
Deprecate source mode in mappings (#117177)
Backport of #116689 to 8.18
1 parent b74c665 commit bfdde9b

File tree

32 files changed

+289
-149
lines changed

32 files changed

+289
-149
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/compat/compat/RestCompatTestTransformTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public void skipTest(String fullTestName, String reason) {
135135
// For example: indices.get_mapping/20_missing_type/Non-existent type returns 404
136136
// However, the folder can be arbitrarily nest so, a == a1/a2/a3, and the test name can include forward slashes, so c == c1/c2/c3
137137
// So we also need to support a1/a2/a3/b/c1/c2/c3
138-
139-
String[] testParts = fullTestName.split("/");
138+
boolean limitTo3Separators = fullTestName.equals("logsdb/20_source_mapping/include/exclude is supported with stored _source");
139+
String[] testParts = limitTo3Separators ? fullTestName.split("/", 3) : fullTestName.split("/");
140140
if (testParts.length < 3) {
141141
throw new IllegalArgumentException(
142142
"To skip tests, all 3 parts [folder/file/test name] must be defined. found [" + fullTestName + "]"

docs/changelog/116689.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pr: 116689
2+
summary: Deprecate `_source.mode` in mappings
3+
area: Mapping
4+
type: deprecation
5+
issues: []
6+
deprecation:
7+
title: Deprecate `_source.mode` in mappings
8+
area: Mapping
9+
details: Configuring `_source.mode` in mappings is deprecated and will be removed in future versions. Use `index.mapping.source.mode` index setting instead.
10+
impact: Use `index.mapping.source.mode` index setting instead

modules/data-streams/src/test/java/org/elasticsearch/datastreams/mapper/DataStreamTimestampFieldMapperTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ protected void registerParameters(ParameterChecker checker) throws IOException {
4848
checker.registerConflictCheck(
4949
"enabled",
5050
timestampMapping(true, b -> b.startObject("@timestamp").field("type", "date").endObject()),
51-
timestampMapping(false, b -> b.startObject("@timestamp").field("type", "date").endObject())
51+
timestampMapping(false, b -> b.startObject("@timestamp").field("type", "date").endObject()),
52+
dm -> {}
5253
);
5354
checker.registerUpdateCheck(
5455
timestampMapping(false, b -> b.startObject("@timestamp").field("type", "date").endObject()),

qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/LogsIndexModeFullClusterRestartIT.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.common.network.InetAddresses;
1818
import org.elasticsearch.common.time.DateFormatter;
1919
import org.elasticsearch.common.time.FormatNames;
20-
import org.elasticsearch.test.MapMatcher;
2120
import org.elasticsearch.test.cluster.ElasticsearchCluster;
2221
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
2322
import org.elasticsearch.test.rest.RestTestLegacyFeatures;
@@ -31,9 +30,6 @@
3130
import java.util.Map;
3231
import java.util.function.Supplier;
3332

34-
import static org.elasticsearch.test.MapMatcher.assertMap;
35-
import static org.elasticsearch.test.MapMatcher.matchesMap;
36-
3733
public class LogsIndexModeFullClusterRestartIT extends ParameterizedFullClusterRestartTestCase {
3834

3935
@ClassRule
@@ -172,22 +168,16 @@ public void testLogsIndexing() throws IOException {
172168
assertOK(bulkIndexResponse);
173169
assertThat(entityAsMap(bulkIndexResponse).get("errors"), Matchers.is(false));
174170

175-
assertIndexMappingsAndSettings(0, Matchers.nullValue(), matchesMap().extraOk());
176-
assertIndexMappingsAndSettings(
177-
1,
178-
Matchers.equalTo("logsdb"),
179-
matchesMap().extraOk().entry("_source", Map.of("mode", "synthetic"))
180-
);
171+
assertIndexSettings(0, Matchers.nullValue());
172+
assertIndexSettings(1, Matchers.equalTo("logsdb"));
181173
}
182174
}
183175

184-
private void assertIndexMappingsAndSettings(int backingIndex, final Matcher<Object> indexModeMatcher, final MapMatcher mappingsMatcher)
185-
throws IOException {
176+
private void assertIndexSettings(int backingIndex, final Matcher<Object> indexModeMatcher) throws IOException {
186177
assertThat(
187178
getSettings(client(), getWriteBackingIndex(client(), "logs-apache-production", backingIndex)).get("index.mode"),
188179
indexModeMatcher
189180
);
190-
assertMap(getIndexMappingAsMap(getWriteBackingIndex(client(), "logs-apache-production", backingIndex)), mappingsMatcher);
191181
}
192182

193183
private static Request createDataStream(final String dataStreamName) {

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/IndexingIT.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.common.Strings;
1919
import org.elasticsearch.common.time.DateUtils;
2020
import org.elasticsearch.common.xcontent.support.XContentMapValues;
21+
import org.elasticsearch.index.IndexVersions;
2122
import org.elasticsearch.index.mapper.DateFieldMapper;
2223
import org.elasticsearch.index.mapper.TimeSeriesIdFieldMapper;
2324
import org.elasticsearch.test.ListMatcher;
@@ -419,9 +420,15 @@ public void testSyntheticSource() throws IOException {
419420
if (isOldCluster()) {
420421
Request createIndex = new Request("PUT", "/synthetic");
421422
XContentBuilder indexSpec = XContentBuilder.builder(XContentType.JSON.xContent()).startObject();
423+
boolean useIndexSetting = getOldClusterIndexVersion().onOrAfter(IndexVersions.DEPRECATE_SOURCE_MODE_MAPPER);
424+
if (useIndexSetting) {
425+
indexSpec.startObject("settings").field("index.mapping.source.mode", "synthetic").endObject();
426+
}
422427
indexSpec.startObject("mappings");
423428
{
424-
indexSpec.startObject("_source").field("mode", "synthetic").endObject();
429+
if (useIndexSetting == false) {
430+
indexSpec.startObject("_source").field("mode", "synthetic").endObject();
431+
}
425432
indexSpec.startObject("properties").startObject("kwd").field("type", "keyword").endObject().endObject();
426433
}
427434
indexSpec.endObject();

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/LogsIndexModeRollingUpgradeIT.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.common.network.InetAddresses;
1818
import org.elasticsearch.common.time.DateFormatter;
1919
import org.elasticsearch.common.time.FormatNames;
20-
import org.elasticsearch.test.MapMatcher;
2120
import org.elasticsearch.test.cluster.ElasticsearchCluster;
2221
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
2322
import org.hamcrest.Matcher;
@@ -30,9 +29,6 @@
3029
import java.util.Map;
3130
import java.util.function.Supplier;
3231

33-
import static org.elasticsearch.test.MapMatcher.assertMap;
34-
import static org.elasticsearch.test.MapMatcher.matchesMap;
35-
3632
public class LogsIndexModeRollingUpgradeIT extends AbstractRollingUpgradeTestCase {
3733

3834
@ClassRule()
@@ -160,14 +156,10 @@ public void testLogsIndexing() throws IOException {
160156
assertOK(bulkIndexResponse);
161157
assertThat(entityAsMap(bulkIndexResponse).get("errors"), Matchers.is(false));
162158

163-
assertIndexMappingsAndSettings(0, Matchers.nullValue(), matchesMap().extraOk());
164-
assertIndexMappingsAndSettings(1, Matchers.nullValue(), matchesMap().extraOk());
165-
assertIndexMappingsAndSettings(2, Matchers.nullValue(), matchesMap().extraOk());
166-
assertIndexMappingsAndSettings(
167-
3,
168-
Matchers.equalTo("logsdb"),
169-
matchesMap().extraOk().entry("_source", Map.of("mode", "synthetic"))
170-
);
159+
assertIndexSettings(0, Matchers.nullValue());
160+
assertIndexSettings(1, Matchers.nullValue());
161+
assertIndexSettings(2, Matchers.nullValue());
162+
assertIndexSettings(3, Matchers.equalTo("logsdb"));
171163
}
172164
}
173165

@@ -183,13 +175,11 @@ static void enableLogsdbByDefault() throws IOException {
183175
assertOK(client().performRequest(request));
184176
}
185177

186-
private void assertIndexMappingsAndSettings(int backingIndex, final Matcher<Object> indexModeMatcher, final MapMatcher mappingsMatcher)
187-
throws IOException {
178+
private void assertIndexSettings(int backingIndex, final Matcher<Object> indexModeMatcher) throws IOException {
188179
assertThat(
189180
getSettings(client(), getWriteBackingIndex(client(), "logs-apache-production", backingIndex)).get("index.mode"),
190181
indexModeMatcher
191182
);
192-
assertMap(getIndexMappingAsMap(getWriteBackingIndex(client(), "logs-apache-production", backingIndex)), mappingsMatcher);
193183
}
194184

195185
private static Request createDataStream(final String dataStreamName) {

rest-api-spec/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,10 @@ tasks.named("precommit").configure {
247247
tasks.named("yamlRestTestV7CompatTransform").configure({ task ->
248248
task.skipTest("indices.sort/10_basic/Index Sort", "warning does not exist for compatibility")
249249
task.skipTest("search/330_fetch_fields/Test search rewrite", "warning does not exist for compatibility")
250+
task.skipTest("tsdb/20_mapping/stored source is supported", "no longer serialize source_mode")
251+
task.skipTest("tsdb/20_mapping/Synthetic source", "no longer serialize source_mode")
252+
task.skipTest("logsdb/10_settings/create logs index", "no longer serialize source_mode")
253+
task.skipTest("logsdb/20_source_mapping/stored _source mode is supported", "no longer serialize source_mode")
254+
task.skipTest("logsdb/20_source_mapping/include/exclude is supported with stored _source", "no longer serialize source_mode")
255+
task.skipTest("logsdb/20_source_mapping/synthetic _source is default", "no longer serialize source_mode")
250256
})

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/logsdb/10_settings.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ create logs index:
7777
- is_true: test
7878
- match: { test.settings.index.mode: "logsdb" }
7979

80-
- do:
81-
indices.get_mapping:
82-
index: test
83-
- match: { test.mappings._source.mode: synthetic }
84-
8580
---
8681
using default timestamp field mapping:
8782
- requires:

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/logsdb/20_source_mapping.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ synthetic _source is default:
1313
index:
1414
mode: logsdb
1515
- do:
16-
indices.get:
16+
indices.get_settings:
1717
index: test-default-source
18-
19-
- match: { test-default-source.mappings._source.mode: "synthetic" }
18+
- match: { test-default-source.settings.index.mode: logsdb }
19+
- match: { test-default-source.settings.index.mapping.source.mode: null }
2020

2121
---
2222
stored _source mode is supported:
@@ -28,11 +28,12 @@ stored _source mode is supported:
2828
index:
2929
mode: logsdb
3030
mapping.source.mode: stored
31+
3132
- do:
32-
indices.get:
33+
indices.get_settings:
3334
index: test-stored-source
34-
35-
- match: { test-stored-source.mappings._source.mode: "stored" }
35+
- match: { test-stored-source.settings.index.mode: logsdb }
36+
- match: { test-stored-source.settings.index.mapping.source.mode: stored }
3637

3738
---
3839
disabled _source is not supported:
@@ -110,7 +111,6 @@ include/exclude is supported with stored _source:
110111
indices.get:
111112
index: test-includes
112113

113-
- match: { test-includes.mappings._source.mode: "stored" }
114114
- match: { test-includes.mappings._source.includes: ["a"] }
115115

116116
- do:
@@ -129,5 +129,4 @@ include/exclude is supported with stored _source:
129129
indices.get:
130130
index: test-excludes
131131

132-
- match: { test-excludes.mappings._source.mode: "stored" }
133132
- match: { test-excludes.mappings._source.excludes: ["b"] }

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,6 @@ nested fields:
450450
type: long
451451
time_series_metric: gauge
452452

453-
- do:
454-
indices.get_mapping: {}
455-
456-
- match: {tsdb-synthetic.mappings._source.mode: synthetic}
457-
458453
---
459454
stored source is supported:
460455
- requires:
@@ -486,12 +481,6 @@ stored source is supported:
486481
type: keyword
487482
time_series_dimension: true
488483

489-
- do:
490-
indices.get:
491-
index: tsdb_index
492-
493-
- match: { tsdb_index.mappings._source.mode: "stored" }
494-
495484
---
496485
disabled source is not supported:
497486
- requires:

0 commit comments

Comments
 (0)