Skip to content

Commit cd10b05

Browse files
authored
Turn _source meta fieldmapper's mode attribute into a no-op. (#119072)
Closes #118596
1 parent 7b47ba9 commit cd10b05

File tree

23 files changed

+401
-630
lines changed

23 files changed

+401
-630
lines changed

docs/changelog/119072.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pr: 119072
2+
summary: Turn `_source` meta fieldmapper's mode attribute into a no-op
3+
area: Mapping
4+
type: breaking
5+
issues:
6+
- 118596
7+
breaking:
8+
title: Turn `_source` meta fieldmapper's mode attribute into a no-op
9+
area: Mapping
10+
details: The `mode` mapping attribute of `_source` metadata field mapper has been turned into a no-op. Instead the `index.mapping.source.mode` index setting should be used to configure source mode.
11+
impact: Configuring the `mode` attribute for the `_source` meta field mapper will have no effect on indices created with Elasticsearch 9.0.0 or later. Note that `_source.mode` configured on indices before upgrading to 9.0.0 or later will remain efficive after upgrading.
12+
notable: false
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.upgrades;
11+
12+
import com.carrotsearch.randomizedtesting.annotations.Name;
13+
14+
import org.elasticsearch.client.Request;
15+
import org.elasticsearch.index.mapper.SourceFieldMapper;
16+
17+
import java.io.IOException;
18+
import java.util.List;
19+
import java.util.Map;
20+
21+
import static org.hamcrest.Matchers.containsString;
22+
import static org.hamcrest.Matchers.equalTo;
23+
24+
public class SourceModeRollingUpgradeIT extends AbstractRollingUpgradeTestCase {
25+
26+
public SourceModeRollingUpgradeIT(@Name("upgradedNodes") int upgradedNodes) {
27+
super(upgradedNodes);
28+
}
29+
30+
public void testConfigureStoredSourceBeforeIndexCreationLegacy() throws IOException {
31+
assumeTrue("testing deprecation warnings and deprecation migrations", getOldClusterTestVersion().before("9.0.0"));
32+
String templateName = "logs@custom";
33+
if (isOldCluster()) {
34+
var storedSourceMapping = """
35+
{
36+
"template": {
37+
"settings": {
38+
"index": {
39+
"mode": "logsdb"
40+
}
41+
},
42+
"mappings": {
43+
"_source": {
44+
"mode": "stored"
45+
}
46+
}
47+
}
48+
}""";
49+
var putComponentTemplateRequest = new Request("PUT", "/_component_template/" + templateName);
50+
putComponentTemplateRequest.setOptions(expectWarnings(SourceFieldMapper.DEPRECATION_WARNING));
51+
putComponentTemplateRequest.setJsonEntity(storedSourceMapping);
52+
assertOK(client().performRequest(putComponentTemplateRequest));
53+
54+
var request = new Request("GET", "/_migration/deprecations");
55+
var nodeSettings = (Map<?, ?>) ((List<?>) entityAsMap(client().performRequest(request)).get("node_settings")).getFirst();
56+
assertThat(nodeSettings.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING));
57+
assertThat(
58+
(String) nodeSettings.get("details"),
59+
containsString(SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [" + templateName + "]")
60+
);
61+
} else if (isUpgradedCluster()) {
62+
var request = new Request("GET", "/_migration/deprecations");
63+
var nodeSettings = (Map<?, ?>) ((List<?>) entityAsMap(client().performRequest(request)).get("node_settings")).getFirst();
64+
assertThat(nodeSettings.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING));
65+
assertThat(
66+
(String) nodeSettings.get("details"),
67+
containsString(SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [" + templateName + "]")
68+
);
69+
}
70+
}
71+
72+
public void testConfigureStoredSourceWhenIndexIsCreatedLegacy() throws IOException {
73+
assumeTrue("testing deprecation warnings and deprecation migrations", getOldClusterTestVersion().before("9.0.0"));
74+
String templateName = "logs@custom";
75+
if (isOldCluster()) {
76+
var storedSourceMapping = """
77+
{
78+
"template": {
79+
"mappings": {
80+
"_source": {
81+
"mode": "stored"
82+
}
83+
}
84+
}
85+
}""";
86+
var putComponentTemplateRequest = new Request("PUT", "/_component_template/" + templateName);
87+
putComponentTemplateRequest.setOptions(expectWarnings(SourceFieldMapper.DEPRECATION_WARNING));
88+
putComponentTemplateRequest.setJsonEntity(storedSourceMapping);
89+
assertOK(client().performRequest(putComponentTemplateRequest));
90+
91+
var request = new Request("GET", "/_migration/deprecations");
92+
var nodeSettings = (Map<?, ?>) ((List<?>) entityAsMap(client().performRequest(request)).get("node_settings")).getFirst();
93+
assertThat(nodeSettings.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING));
94+
assertThat(
95+
(String) nodeSettings.get("details"),
96+
containsString(SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [" + templateName + "]")
97+
);
98+
} else if (isUpgradedCluster()) {
99+
var request = new Request("GET", "/_migration/deprecations");
100+
var nodeSettings = (Map<?, ?>) ((List<?>) entityAsMap(client().performRequest(request)).get("node_settings")).getFirst();
101+
assertThat(nodeSettings.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING));
102+
assertThat(
103+
(String) nodeSettings.get("details"),
104+
containsString(SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [" + templateName + "]")
105+
);
106+
}
107+
}
108+
}

rest-api-spec/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,15 @@ tasks.named("yamlRestCompatTestTransform").configure ({ task ->
8787
task.skipTest("search.highlight/30_max_analyzed_offset/Plain highlighter with max_analyzed_offset < 0 should FAIL", "semantics of test has changed")
8888
task.skipTest("indices.create/10_basic/Create lookup index", "default auto_expand_replicas was removed")
8989
task.skipTest("indices.create/10_basic/Create lookup index with one shard", "default auto_expand_replicas was removed")
90+
task.skipTest("range/20_synthetic_source/Double range", "_source.mode mapping attribute is no-op since 9.0.0")
91+
task.skipTest("range/20_synthetic_source/Float range", "_source.mode mapping attribute is no-op since 9.0.0")
92+
task.skipTest("range/20_synthetic_source/Integer range", "_source.mode mapping attribute is no-op since 9.0.0")
93+
task.skipTest("range/20_synthetic_source/IP range", "_source.mode mapping attribute is no-op since 9.0.0")
94+
task.skipTest("range/20_synthetic_source/Long range", "_source.mode mapping attribute is no-op since 9.0.0")
95+
task.skipTest("range/20_synthetic_source/Date range Rounding Fixes", "_source.mode mapping attribute is no-op since 9.0.0")
96+
task.skipTest("index/92_metrics_auto_subobjects/Metrics object indexing with synthetic source", "_source.mode mapping attribute is no-op since 9.0.0")
97+
task.skipTest("index/92_metrics_auto_subobjects/Root without subobjects with synthetic source", "_source.mode mapping attribute is no-op since 9.0.0")
98+
task.skipTest("index/91_metrics_no_subobjects/Metrics object indexing with synthetic source", "_source.mode mapping attribute is no-op since 9.0.0")
99+
task.skipTest("index/91_metrics_no_subobjects/Root without subobjects with synthetic source", "_source.mode mapping attribute is no-op since 9.0.0")
100+
task.skipTest("logsdb/10_settings/routing path allowed in logs mode with routing on sort fields", "Unknown feature routing.logsb_route_on_sort_fields")
90101
})

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/index/91_metrics_no_subobjects.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@
142142
body:
143143
index_patterns: test-*
144144
template:
145+
settings:
146+
index.mapping.source.mode: synthetic
145147
mappings:
146-
_source:
147-
mode: synthetic
148148
dynamic_templates:
149149
- no_subobjects:
150150
match: metrics
@@ -212,9 +212,9 @@
212212
body:
213213
index_patterns: test-*
214214
template:
215+
settings:
216+
index.mapping.source.mode: synthetic
215217
mappings:
216-
_source:
217-
mode: synthetic
218218
subobjects: false
219219
properties:
220220
host.name:

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/index/92_metrics_auto_subobjects.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@
139139
body:
140140
index_patterns: test-*
141141
template:
142+
settings:
143+
index.mapping.source.mode: synthetic
142144
mappings:
143-
_source:
144-
mode: synthetic
145145
dynamic_templates:
146146
- no_subobjects:
147147
match: metrics
@@ -208,9 +208,9 @@
208208
body:
209209
index_patterns: test-*
210210
template:
211+
settings:
212+
index.mapping.source.mode: synthetic
211213
mappings:
212-
_source:
213-
mode: synthetic
214214
subobjects: auto
215215
properties:
216216
host.name:

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/range/20_synthetic_source.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ setup:
77
indices.create:
88
index: synthetic_source_test
99
body:
10+
settings:
11+
index.mapping.source.mode: synthetic
1012
mappings:
11-
"_source":
12-
"mode": "synthetic"
1313
"properties":
1414
"integer_range":
1515
"type" : "integer_range"

server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/NestedIT.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
1313
import org.elasticsearch.action.index.IndexRequestBuilder;
1414
import org.elasticsearch.action.search.SearchRequestBuilder;
15+
import org.elasticsearch.common.settings.Settings;
1516
import org.elasticsearch.index.query.InnerHitBuilder;
1617
import org.elasticsearch.rest.RestStatus;
1718
import org.elasticsearch.search.SearchHit;
@@ -857,24 +858,22 @@ public void testExtractInnerHitBuildersWithDuplicatePath() throws Exception {
857858

858859
public void testSyntheticSource() throws Exception {
859860
assertAcked(
860-
prepareCreate("synthetic").setMapping(
861-
jsonBuilder().startObject()
862-
.startObject("_source")
863-
.field("mode", "synthetic")
864-
.endObject()
865-
.startObject("properties")
866-
.startObject("nested")
867-
.field("type", "nested")
868-
.startObject("properties")
869-
.startObject("number")
870-
.field("type", "long")
871-
.field("ignore_malformed", true)
872-
.endObject()
873-
.endObject()
874-
.endObject()
875-
.endObject()
876-
.endObject()
877-
)
861+
prepareCreate("synthetic").setSettings(Settings.builder().put("index.mapping.source.mode", "synthetic").build())
862+
.setMapping(
863+
jsonBuilder().startObject()
864+
.startObject("properties")
865+
.startObject("nested")
866+
.field("type", "nested")
867+
.startObject("properties")
868+
.startObject("number")
869+
.field("type", "long")
870+
.field("ignore_malformed", true)
871+
.endObject()
872+
.endObject()
873+
.endObject()
874+
.endObject()
875+
.endObject()
876+
)
878877
);
879878
ensureGreen("synthetic");
880879

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ private static Version parseUnchecked(String version) {
142142
public static final IndexVersion USE_SYNTHETIC_SOURCE_FOR_RECOVERY = def(9_004_00_0, Version.LUCENE_10_0_0);
143143
public static final IndexVersion INFERENCE_METADATA_FIELDS = def(9_005_00_0, Version.LUCENE_10_0_0);
144144
public static final IndexVersion LOGSB_OPTIONAL_SORTING_ON_HOST_NAME = def(9_006_00_0, Version.LUCENE_10_0_0);
145+
public static final IndexVersion SOURCE_MAPPER_MODE_ATTRIBUTE_NOOP = def(9_007_00_0, Version.LUCENE_10_0_0);
145146
/*
146147
* STOP! READ THIS FIRST! No, really,
147148
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

0 commit comments

Comments
 (0)