Browse Source

Register `indices.query.bool.max_clause_count` setting (#18341)

* Register `indices.query.bool.max_clause_count` setting

This commit registers `indices.query.bool.max_clause_count` as a node
level setting and removes support for its synonym setting
`index.query.bool.max_clause_count`.

Closes #18336
Simon Willnauer 9 years ago
parent
commit
d77c299cb9

+ 3 - 1
core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java

@@ -87,6 +87,7 @@ import org.elasticsearch.repositories.fs.FsRepository;
 import org.elasticsearch.repositories.uri.URLRepository;
 import org.elasticsearch.rest.BaseRestHandler;
 import org.elasticsearch.script.ScriptService;
+import org.elasticsearch.search.SearchModule;
 import org.elasticsearch.search.SearchService;
 import org.elasticsearch.threadpool.ThreadPool;
 import org.elasticsearch.transport.Transport;
@@ -420,6 +421,7 @@ public final class ClusterSettings extends AbstractScopedSettings {
                     ResourceWatcherService.ENABLED,
                     ResourceWatcherService.RELOAD_INTERVAL_HIGH,
                     ResourceWatcherService.RELOAD_INTERVAL_MEDIUM,
-                    ResourceWatcherService.RELOAD_INTERVAL_LOW
+                    ResourceWatcherService.RELOAD_INTERVAL_LOW,
+                    SearchModule.INDICES_MAX_CLAUSE_COUNT_SETTING
             )));
 }

+ 6 - 1
core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java

@@ -65,7 +65,12 @@ public class SettingsModule extends AbstractModule {
     protected void configure() {
         final IndexScopedSettings indexScopedSettings = new IndexScopedSettings(settings, new HashSet<>(this.indexSettings.values()));
         final ClusterSettings clusterSettings = new ClusterSettings(settings, new HashSet<>(this.nodeSettings.values()));
-        Settings indexSettings = settings.filter((s) -> s.startsWith("index.") && clusterSettings.get(s) == null);
+        Settings indexSettings = settings.filter((s) -> (s.startsWith("index.") &&
+            // special case - we want to get Did you mean indices.query.bool.max_clause_count
+            // which means we need to by-pass this check for this setting
+            // TODO remove in 6.0!!
+            "index.query.bool.max_clause_count".equals(s) == false)
+            && clusterSettings.get(s) == null);
         if (indexSettings.isEmpty() == false) {
             try {
                 String separator = IntStream.range(0, 85).mapToObj(s -> "*").collect(Collectors.joining("")).trim();

+ 4 - 2
core/src/main/java/org/elasticsearch/search/SearchModule.java

@@ -29,6 +29,7 @@ import org.elasticsearch.common.io.stream.NamedWriteable;
 import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
 import org.elasticsearch.common.io.stream.Writeable;
 import org.elasticsearch.common.lucene.search.function.ScoreFunction;
+import org.elasticsearch.common.settings.Setting;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.xcontent.ParseFieldRegistry;
 import org.elasticsearch.index.percolator.PercolatorHighlightSubFetchPhase;
@@ -290,6 +291,8 @@ public class SearchModule extends AbstractModule {
 
     private final Settings settings;
     private final NamedWriteableRegistry namedWriteableRegistry;
+    public static final Setting<Integer> INDICES_MAX_CLAUSE_COUNT_SETTING = Setting.intSetting("indices.query.bool.max_clause_count",
+        1024, 1, Integer.MAX_VALUE, Setting.Property.NodeScope);
 
     // pkg private so tests can mock
     Class<? extends SearchService> searchServiceImpl = SearchService.class;
@@ -650,8 +653,7 @@ public class SearchModule extends AbstractModule {
         registerQuery(MatchAllQueryBuilder::new, MatchAllQueryBuilder::fromXContent, MatchAllQueryBuilder.QUERY_NAME_FIELD);
         registerQuery(QueryStringQueryBuilder::new, QueryStringQueryBuilder::fromXContent, QueryStringQueryBuilder.QUERY_NAME_FIELD);
         registerQuery(BoostingQueryBuilder::new, BoostingQueryBuilder::fromXContent, BoostingQueryBuilder.QUERY_NAME_FIELD);
-        BooleanQuery.setMaxClauseCount(settings.getAsInt("index.query.bool.max_clause_count",
-                settings.getAsInt("indices.query.bool.max_clause_count", BooleanQuery.getMaxClauseCount())));
+        BooleanQuery.setMaxClauseCount(INDICES_MAX_CLAUSE_COUNT_SETTING.get(settings));
         registerQuery(BoolQueryBuilder::new, BoolQueryBuilder::fromXContent, BoolQueryBuilder.QUERY_NAME_FIELD);
         registerQuery(TermQueryBuilder::new, TermQueryBuilder::fromXContent, TermQueryBuilder.QUERY_NAME_FIELD);
         registerQuery(TermsQueryBuilder::new, TermsQueryBuilder::fromXContent, TermsQueryBuilder.QUERY_NAME_FIELD);

+ 9 - 0
core/src/test/java/org/elasticsearch/common/settings/SettingsModuleTests.java

@@ -208,4 +208,13 @@ public class SettingsModuleTests extends ModuleTestCase {
             assertThat(e.getMessage(), containsString("Cannot register setting [foo.bar] twice"));
         }
     }
+
+    public void testOldMaxClauseCountSetting() {
+            Settings settings = Settings.builder().put("index.query.bool.max_clause_count", 1024).build();
+            SettingsModule module = new SettingsModule(settings);
+            IllegalArgumentException ex = expectThrows(IllegalArgumentException.class,
+                () -> assertInstanceBinding(module, Settings.class, (s) -> s == settings));
+            assertEquals("unknown setting [index.query.bool.max_clause_count] did you mean [indices.query.bool.max_clause_count]?",
+                ex.getMessage());
+    }
 }

+ 6 - 0
docs/reference/migration/migrate_5_0/settings.asciidoc

@@ -258,3 +258,9 @@ Previously script mode settings (e.g., "script.inline: true",
 Prior to 5.0 a third option could be specified for the `script.inline` and
 `script.stored` settings ("sandbox"). This has been removed, You can now only
 set `script.line: true` or `script.stored: true`.
+
+==== Search settings
+
+The setting `index.query.bool.max_clause_count` has been removed. In order to
+set the maximum number of boolean clauses `indices.query.bool.max_clause_count`
+should be used instead.