Skip to content

Commit e833e7b

Browse files
authored
Add feature flag for subobjects auto (elastic#114616)
1 parent edcabb8 commit e833e7b

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
@@ -1377,6 +1377,7 @@ public void testSubobjectsFalseWithInnerNestedFromDynamicTemplate() {
13771377
}
13781378

13791379
public void testSubobjectsAutoFlatPaths() throws IOException {
1380+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
13801381
MapperService mapperService = createDynamicTemplateAutoSubobjects();
13811382
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> {
13821383
b.field("foo.metric.count", 10);
@@ -1389,6 +1390,7 @@ public void testSubobjectsAutoFlatPaths() throws IOException {
13891390
}
13901391

13911392
public void testSubobjectsAutoStructuredPaths() throws IOException {
1393+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
13921394
MapperService mapperService = createDynamicTemplateAutoSubobjects();
13931395
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> {
13941396
b.startObject("foo");
@@ -1411,6 +1413,7 @@ public void testSubobjectsAutoStructuredPaths() throws IOException {
14111413
}
14121414

14131415
public void testSubobjectsAutoArrayOfObjects() throws IOException {
1416+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
14141417
MapperService mapperService = createDynamicTemplateAutoSubobjects();
14151418
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> {
14161419
b.startObject("foo");
@@ -1444,6 +1447,7 @@ public void testSubobjectsAutoArrayOfObjects() throws IOException {
14441447
}
14451448

14461449
public void testSubobjectAutoDynamicNested() throws IOException {
1450+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
14471451
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
14481452
b.startArray("dynamic_templates");
14491453
{
@@ -1482,6 +1486,7 @@ public void testSubobjectAutoDynamicNested() throws IOException {
14821486
}
14831487

14841488
public void testRootSubobjectAutoDynamicNested() throws IOException {
1489+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
14851490
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
14861491
b.startArray("dynamic_templates");
14871492
{
@@ -1515,6 +1520,7 @@ public void testRootSubobjectAutoDynamicNested() throws IOException {
15151520
}
15161521

15171522
public void testDynamicSubobjectsAutoDynamicFalse() throws Exception {
1523+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
15181524
// verify that we read the dynamic value properly from the parent mapper. DocumentParser#dynamicOrDefault splits the field
15191525
// 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
15201526
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
@@ -1578,6 +1584,7 @@ public void testDynamicSubobjectsAutoDynamicFalse() throws Exception {
15781584
}
15791585

15801586
public void testSubobjectsAutoWithInnerNestedFromDynamicTemplate() throws IOException {
1587+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
15811588
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
15821589
b.startArray("dynamic_templates");
15831590
{
@@ -2045,6 +2052,7 @@ public void testSubobjectsFalseFlattened() throws IOException {
20452052
}
20462053

20472054
public void testSubobjectsAutoFlattened() throws IOException {
2055+
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
20482056
String mapping = """
20492057
{
20502058
"_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
CHUNKING_SETTINGS_ENABLED("es.inference_chunking_settings_feature_flag_enabled=true", Version.fromString("8.16.0"), null),
2223
INFERENCE_DEFAULT_ELSER("es.inference_default_elser_feature_flag_enabled=true", Version.fromString("8.16.0"), null);
2324

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) {

x-pack/qa/runtime-fields/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ subprojects {
4444
setting 'xpack.security.enabled', 'false'
4545

4646
requiresFeature 'es.index_mode_feature_flag_registered', Version.fromString("8.0.0")
47+
requiresFeature 'es.sub_objects_auto_feature_flag_enabled', Version.fromString("8.16.0")
4748
}
4849

4950
tasks.named("yamlRestTest").configure {

0 commit comments

Comments
 (0)