Skip to content

[BUG] TermsQueryBuilder uses wrong setting key for max_clause_countΒ #20820

@bcsimoes

Description

@bcsimoes

Describe the bug

In TermsQueryBuilder.java (line 611), the terms lookup fetch-size logic reads the setting key "indices.query.max_clause_count" instead of the correct "indices.query.bool.max_clause_count".

// Current (incorrect) β€” TermsQueryBuilder.java:611
int maxClauseCount = idxSettings.getAsInt("indices.query.max_clause_count", 1024);

The correct setting key, as defined in SearchService.INDICES_MAX_CLAUSE_COUNT_SETTING, is:

// SearchService.java:398
"indices.query.bool.max_clause_count"

Because "indices.query.max_clause_count" is never a registered setting, getAsInt always falls back to the hardcoded default of 1024, making any user/operator configuration of indices.query.bool.max_clause_count silently ignored when computing the terms lookup fetch size.

To reproduce

  1. Set the cluster setting indices.query.bool.max_clause_count to a value other than 1024 (e.g., 4096).
  2. Run a terms query with a terms_lookup that would benefit from a larger fetch size.
  3. Observe that the fetch size is still capped at 1024 regardless of the configured value.

Expected behavior

The terms lookup fetch-size calculation should read "indices.query.bool.max_clause_count" (or ideally use the typed SearchService.INDICES_MAX_CLAUSE_COUNT_SETTING constant) so that the operator-configured value is respected.

Suggested fix

// Option A: Use the typed Setting (preferred)
int maxClauseCount = SearchService.INDICES_MAX_CLAUSE_COUNT_SETTING.get(idxSettings);

// Option B: Use the correct string key
int maxClauseCount = idxSettings.getAsInt("indices.query.bool.max_clause_count", 1024);

The test in TermQueryWithDocIdAndQueryTests.java:380 also uses the wrong key and should be updated to match.

OpenSearch version

main (HEAD)

Operating system

All

Additional context

The .bool. segment was likely dropped during development. The setting was made dynamically updateable in #13568 (2.16.0), but this code path was not updated to use the correct key.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SearchSearch query, autocomplete ...etcserver

    Type

    No type

    Projects

    Status

    βœ… Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions