diff --git a/core/src/main/java/org/elasticsearch/common/settings/Setting.java b/core/src/main/java/org/elasticsearch/common/settings/Setting.java index ed113b0d51b..edd5d511f86 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/Setting.java +++ b/core/src/main/java/org/elasticsearch/common/settings/Setting.java @@ -344,7 +344,7 @@ public class Setting extends ToXContentToBytes { return get(primary); } if (fallbackSetting == null) { - return get(secondary); + return get(secondary); } if (exists(secondary)) { return get(secondary); @@ -599,7 +599,6 @@ public class Setting extends ToXContentToBytes { return new Setting>(new ListKey(key), (s) -> arrayToParsableString(defaultStringValue.apply(s).toArray(Strings.EMPTY_ARRAY)), parser, properties) { - private final Pattern pattern = Pattern.compile(Pattern.quote(key)+"(\\.\\d+)?"); @Override public String getRaw(Settings settings) { String[] array = settings.getAsArray(getKey(), null); @@ -610,6 +609,12 @@ public class Setting extends ToXContentToBytes { boolean hasComplexMatcher() { return true; } + + @Override + public boolean exists(Settings settings) { + boolean exists = super.exists(settings); + return exists || settings.get(getKey() + ".0") != null; + } }; } diff --git a/core/src/test/java/org/elasticsearch/common/settings/SettingTests.java b/core/src/test/java/org/elasticsearch/common/settings/SettingTests.java index 6153f3b7d71..8b2dbdb4f07 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/SettingTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/SettingTests.java @@ -294,11 +294,13 @@ public class SettingTests extends ESTestCase { Setting> listSetting = Setting.listSetting("foo.bar", Arrays.asList("foo,bar"), (s) -> s.toString(), Property.Dynamic, Property.NodeScope); List value = listSetting.get(Settings.EMPTY); + assertFalse(listSetting.exists(Settings.EMPTY)); assertEquals(1, value.size()); assertEquals("foo,bar", value.get(0)); List input = Arrays.asList("test", "test1, test2", "test", ",,,,"); Settings.Builder builder = Settings.builder().putArray("foo.bar", input.toArray(new String[0])); + assertTrue(listSetting.exists(builder.build())); value = listSetting.get(builder.build()); assertEquals(input.size(), value.size()); assertArrayEquals(value.toArray(new String[0]), input.toArray(new String[0])); @@ -311,6 +313,7 @@ public class SettingTests extends ESTestCase { value = listSetting.get(builder.build()); assertEquals(input.size(), value.size()); assertArrayEquals(value.toArray(new String[0]), input.toArray(new String[0])); + assertTrue(listSetting.exists(builder.build())); AtomicReference> ref = new AtomicReference<>(); AbstractScopedSettings.SettingUpdater> settingUpdater = listSetting.newUpdater(ref::set, logger);