Skip to content

Commit 9348d9f

Browse files
authored
Add feature flag for subobjects auto (#114616) (#114678)
1 parent 006c274 commit 9348d9f

File tree

11 files changed

+49
-23
lines changed

11 files changed

+49
-23
lines changed

qa/ccs-common-rest/src/yamlRestTest/java/org/elasticsearch/test/rest/yaml/CcsCommonYamlTestSuiteIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public class CcsCommonYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
8989
.setting("xpack.security.enabled", "false")
9090
// geohex_grid requires gold license
9191
.setting("xpack.license.self_generated.type", "trial")
92-
.feature(FeatureFlag.TIME_SERIES_MODE);
92+
.feature(FeatureFlag.TIME_SERIES_MODE)
93+
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED);
9394

9495
private static ElasticsearchCluster remoteCluster = ElasticsearchCluster.local()
9596
.name(REMOTE_CLUSTER_NAME)

qa/ccs-common-rest/src/yamlRestTest/java/org/elasticsearch/test/rest/yaml/RcsCcsCommonYamlTestSuiteIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public class RcsCcsCommonYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
9191
.setting("xpack.security.remote_cluster_server.ssl.enabled", "false")
9292
.setting("xpack.security.remote_cluster_client.ssl.enabled", "false")
9393
.feature(FeatureFlag.TIME_SERIES_MODE)
94+
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED)
9495
.user("test_admin", "x-pack-test-password");
9596

9697
private static ElasticsearchCluster fulfillingCluster = ElasticsearchCluster.local()

qa/smoke-test-multinode/src/yamlRestTest/java/org/elasticsearch/smoketest/SmokeTestMultiNodeClientYamlTestSuiteIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class SmokeTestMultiNodeClientYamlTestSuiteIT extends ESClientYamlSuiteTe
3535
// The first node does not have the ingest role so we're sure ingest requests are forwarded:
3636
.node(0, n -> n.setting("node.roles", "[master,data,ml,remote_cluster_client,transform]"))
3737
.feature(FeatureFlag.TIME_SERIES_MODE)
38+
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED)
3839
.build();
3940

4041
public SmokeTestMultiNodeClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {

rest-api-spec/src/yamlRestTest/java/org/elasticsearch/test/rest/ClientYamlTestSuiteIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class ClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
3636
.module("health-shards-availability")
3737
.module("data-streams")
3838
.feature(FeatureFlag.TIME_SERIES_MODE)
39+
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED)
3940
.build();
4041

4142
public ClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.common.Explicit;
1616
import org.elasticsearch.common.logging.DeprecationCategory;
1717
import org.elasticsearch.common.logging.DeprecationLogger;
18+
import org.elasticsearch.common.util.FeatureFlag;
1819
import org.elasticsearch.common.xcontent.support.XContentMapValues;
1920
import org.elasticsearch.core.Nullable;
2021
import org.elasticsearch.features.NodeFeature;
@@ -41,6 +42,7 @@
4142

4243
public class ObjectMapper extends Mapper {
4344
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(ObjectMapper.class);
45+
public static final FeatureFlag SUB_OBJECTS_AUTO_FEATURE_FLAG = new FeatureFlag("sub_objects_auto");
4446

4547
public static final String CONTENT_TYPE = "object";
4648
static final String STORE_ARRAY_SOURCE_PARAM = "store_array_source";
@@ -74,7 +76,7 @@ public static Subobjects from(Object node) {
7476
if (value.equalsIgnoreCase("false")) {
7577
return DISABLED;
7678
}
77-
if (value.equalsIgnoreCase("auto")) {
79+
if (SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled() && value.equalsIgnoreCase("auto")) {
7880
return AUTO;
7981
}
8082
}

server/src/test/java/org/elasticsearch/index/mapper/DynamicTemplatesTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,7 @@ public void testSubobjectsFalseWithInnerNestedFromDynamicTemplate() {
14441444
}
14451445

14461446
public void testSubobjectsAutoFlatPaths() throws IOException {
1447+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
14471448
MapperService mapperService = createDynamicTemplateAutoSubobjects();
14481449
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> {
14491450
b.field("foo.metric.count", 10);
@@ -1456,6 +1457,7 @@ public void testSubobjectsAutoFlatPaths() throws IOException {
14561457
}
14571458

14581459
public void testSubobjectsAutoStructuredPaths() throws IOException {
1460+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
14591461
MapperService mapperService = createDynamicTemplateAutoSubobjects();
14601462
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> {
14611463
b.startObject("foo");
@@ -1478,6 +1480,7 @@ public void testSubobjectsAutoStructuredPaths() throws IOException {
14781480
}
14791481

14801482
public void testSubobjectsAutoArrayOfObjects() throws IOException {
1483+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
14811484
MapperService mapperService = createDynamicTemplateAutoSubobjects();
14821485
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> {
14831486
b.startObject("foo");
@@ -1511,6 +1514,7 @@ public void testSubobjectsAutoArrayOfObjects() throws IOException {
15111514
}
15121515

15131516
public void testSubobjectAutoDynamicNested() throws IOException {
1517+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
15141518
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
15151519
b.startArray("dynamic_templates");
15161520
{
@@ -1549,6 +1553,7 @@ public void testSubobjectAutoDynamicNested() throws IOException {
15491553
}
15501554

15511555
public void testRootSubobjectAutoDynamicNested() throws IOException {
1556+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
15521557
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
15531558
b.startArray("dynamic_templates");
15541559
{
@@ -1582,6 +1587,7 @@ public void testRootSubobjectAutoDynamicNested() throws IOException {
15821587
}
15831588

15841589
public void testDynamicSubobjectsAutoDynamicFalse() throws Exception {
1590+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
15851591
// verify that we read the dynamic value properly from the parent mapper. DocumentParser#dynamicOrDefault splits the field
15861592
// name where dots are found, but it does that only for the parent prefix e.g. metrics.service and not for the leaf suffix time.max
15871593
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
@@ -1645,6 +1651,7 @@ public void testDynamicSubobjectsAutoDynamicFalse() throws Exception {
16451651
}
16461652

16471653
public void testSubobjectsAutoWithInnerNestedFromDynamicTemplate() throws IOException {
1654+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
16481655
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
16491656
b.startArray("dynamic_templates");
16501657
{
@@ -2112,6 +2119,7 @@ public void testSubobjectsFalseFlattened() throws IOException {
21122119
}
21132120

21142121
public void testSubobjectsAutoFlattened() throws IOException {
2122+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
21152123
String mapping = """
21162124
{
21172125
"_doc": {

server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,27 +169,29 @@ public void testMergeEnabledForIndexTemplates() throws IOException {
169169
assertEquals(ObjectMapper.Subobjects.ENABLED, objectMapper.subobjects());
170170
assertTrue(objectMapper.sourceKeepMode().isEmpty());
171171

172-
// Setting 'enabled' to true is allowed, and updates the mapping.
173-
update = Strings.toString(
174-
XContentFactory.jsonBuilder()
175-
.startObject()
176-
.startObject("properties")
177-
.startObject("object")
178-
.field("type", "object")
179-
.field("enabled", true)
180-
.field("subobjects", "auto")
181-
.field(ObjectMapper.STORE_ARRAY_SOURCE_PARAM, true)
182-
.endObject()
183-
.endObject()
184-
.endObject()
185-
);
186-
mapper = mapperService.merge("type", new CompressedXContent(update), MergeReason.INDEX_TEMPLATE);
187-
188-
objectMapper = mapper.mappers().objectMappers().get("object");
189-
assertNotNull(objectMapper);
190-
assertTrue(objectMapper.isEnabled());
191-
assertEquals(ObjectMapper.Subobjects.AUTO, objectMapper.subobjects());
192-
assertEquals(Mapper.SourceKeepMode.ARRAYS, objectMapper.sourceKeepMode().orElse(Mapper.SourceKeepMode.NONE));
172+
if (ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled()) {
173+
// Setting 'enabled' to true is allowed, and updates the mapping.
174+
update = Strings.toString(
175+
XContentFactory.jsonBuilder()
176+
.startObject()
177+
.startObject("properties")
178+
.startObject("object")
179+
.field("type", "object")
180+
.field("enabled", true)
181+
.field("subobjects", "auto")
182+
.field(ObjectMapper.STORE_ARRAY_SOURCE_PARAM, true)
183+
.endObject()
184+
.endObject()
185+
.endObject()
186+
);
187+
mapper = mapperService.merge("type", new CompressedXContent(update), MergeReason.INDEX_TEMPLATE);
188+
189+
objectMapper = mapper.mappers().objectMappers().get("object");
190+
assertNotNull(objectMapper);
191+
assertTrue(objectMapper.isEnabled());
192+
assertEquals(ObjectMapper.Subobjects.AUTO, objectMapper.subobjects());
193+
assertEquals(Mapper.SourceKeepMode.ARRAYS, objectMapper.sourceKeepMode().orElse(Mapper.SourceKeepMode.NONE));
194+
}
193195
}
194196

195197
public void testFieldReplacementForIndexTemplates() throws IOException {
@@ -503,6 +505,7 @@ public void testSubobjectsCannotBeUpdatedOnRoot() throws IOException {
503505
}
504506

505507
public void testSubobjectsAuto() throws Exception {
508+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
506509
MapperService mapperService = createMapperService(mapping(b -> {
507510
b.startObject("metrics.service");
508511
{
@@ -532,6 +535,7 @@ public void testSubobjectsAuto() throws Exception {
532535
}
533536

534537
public void testSubobjectsAutoWithInnerObject() throws IOException {
538+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
535539
MapperService mapperService = createMapperService(mapping(b -> {
536540
b.startObject("metrics.service");
537541
{
@@ -565,6 +569,7 @@ public void testSubobjectsAutoWithInnerObject() throws IOException {
565569
}
566570

567571
public void testSubobjectsAutoWithInnerNested() throws IOException {
572+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
568573
MapperService mapperService = createMapperService(mapping(b -> {
569574
b.startObject("metrics.service");
570575
{
@@ -586,6 +591,7 @@ public void testSubobjectsAutoWithInnerNested() throws IOException {
586591
}
587592

588593
public void testSubobjectsAutoRoot() throws Exception {
594+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
589595
MapperService mapperService = createMapperService(mappingWithSubobjects(b -> {
590596
b.startObject("metrics.service.time");
591597
b.field("type", "long");
@@ -606,6 +612,7 @@ public void testSubobjectsAutoRoot() throws Exception {
606612
}
607613

608614
public void testSubobjectsAutoRootWithInnerObject() throws IOException {
615+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
609616
MapperService mapperService = createMapperService(mappingWithSubobjects(b -> {
610617
b.startObject("metrics.service.time");
611618
{
@@ -626,6 +633,7 @@ public void testSubobjectsAutoRootWithInnerObject() throws IOException {
626633
}
627634

628635
public void testSubobjectsAutoRootWithInnerNested() throws IOException {
636+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
629637
MapperService mapperService = createMapperService(mappingWithSubobjects(b -> {
630638
b.startObject("metrics.service");
631639
b.field("type", "nested");

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/FeatureFlag.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
public enum FeatureFlag {
1919
TIME_SERIES_MODE("es.index_mode_feature_flag_registered=true", Version.fromString("8.0.0"), null),
2020
FAILURE_STORE_ENABLED("es.failure_store_feature_flag_enabled=true", Version.fromString("8.12.0"), null),
21+
SUB_OBJECTS_AUTO_ENABLED("es.sub_objects_auto_feature_flag_enabled=true", Version.fromString("8.16.0"), null),
2122
INFERENCE_DEFAULT_ELSER("es.inference_default_elser_feature_flag_enabled=true", Version.fromString("8.16.0"), null);
2223

2324
public final String systemProperty;

x-pack/plugin/src/yamlRestTest/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class XPackRestIT extends AbstractXPackRestTest {
4343
.setting("xpack.searchable.snapshot.shared_cache.region_size", "256KB")
4444
.user("x_pack_rest_user", "x-pack-test-password")
4545
.feature(FeatureFlag.TIME_SERIES_MODE)
46+
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED)
4647
.configFile("testnode.pem", Resource.fromClasspath("org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.pem"))
4748
.configFile("testnode.crt", Resource.fromClasspath("org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt"))
4849
.configFile("service_tokens", Resource.fromClasspath("service_tokens"))

x-pack/qa/core-rest-tests-with-security/src/yamlRestTest/java/org/elasticsearch/xpack/security/CoreWithSecurityClientYamlTestSuiteIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class CoreWithSecurityClientYamlTestSuiteIT extends ESClientYamlSuiteTest
4848
.setting("xpack.security.autoconfiguration.enabled", "false")
4949
.user(USER, PASS)
5050
.feature(FeatureFlag.TIME_SERIES_MODE)
51+
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED)
5152
.build();
5253

5354
public CoreWithSecurityClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {

0 commit comments

Comments
 (0)