#23162·OpenSearch

[PERFORMANCE] max_clause_count unexpectedly changes keyword-sort latency since 2.12; persists in 3.8

Author: camerondurhamCreated Sep 29, 2026Updated Sep 30, 2026
LabelsbugSearch:Performance

Describe the bug

Issue

After upgrading from OpenSearch 1.3 to 2.19, my team saw a substantial increase in latency for paginated search_after queries sorted on keyword fields.

While trying to reduce the problem, found an unexpected interaction with indices.query.bool.max_clause_count: lowering it from the default 1024 to 128 recovers much of the lost performance in the reproduction despite the query only containing one boolean clause.

The effect reproduces consistently across multiple machines and appears at the OpenSearch 2.11.1 -> 2.12.0, and remains on 2.19 and 3.8.

Question

Is this expected behavior from Lucene's keyword-sort pruning, or does this look like an undesirable workload-specific performance regression?

If it is a regression, where would the most useful performance coverage live: OpenSearch or Lucene? Should the relationship between max_clause_count and keyword sorting be documented? The setting otherwise looks unrelated to this query.

I'm more than happy to create a PR in the right place to add any test case / benchmark / documentation depending on what maintainers think.

Background

The original production workload uses routed, paginated search_after queries with two keyword sorts. I reduced that down to a standalone synthetic reproduction here:

https://github.com/camerondurham/bug-repro-opensearch-keyword-sort

Relevant graph:

Related component

Search:Performance

To Reproduce

Run a top-N search sorted on a high-cardinality keyword field, then compare the same workload with indices.query.bool.max_clause_count set to 1024 versus 128.

Script: https://github.com/camerondurham/bug-repro-opensearch-keyword-sort/blob/main/minimal_repro.py

It creates a synthetic index with:

  • 198k deterministic documents
  • 18 primary shards, 0 replicas
  • a high-cardinality unique keyword sort field (field_a)
  • a second numeric sort field (field_b) (likely not needed)
  • one keyword tenant field used as a single term filter
  • randomized insertion order so document order is not correlated with the primary sort

Sample query:

json
{
  "size": 250,
  "version": true,
  "query": {
    "bool": {
      "filter": [
        { "term": { "tenant_id": "tenant-a" } }
      ]
    }
  },
  "sort": [
    { "field_a": "asc" },
    { "field_b": "asc" }
  ]
}

Expected behavior

Consistent performance across this workload + max clause configuration and/or having this unexpected side effect of the max clause config documented and included in 1.x to 2.x docs:

Additional Details

Plugins

None, reproduced with stock OpenSearch docker container releases

Screenshots

Performance matrix included above.

Host/Environment (please complete the following information):

Additional context n/a

Source: opensearch-project/OpenSearch