Repository navigation
Description
Is your feature request related to a problem?
The plugin creates a PIT whenever a non-aggregate request needs more rows than index.max_result_window (default 10,000). When the query uses a wildcard index pattern, OpenSearch expands the wildcard and opens one reader context per matching shard, so a broad pattern over hundreds of daily indices can exhaust the per-node search.max_open_pit_context limit (default 300) and the query fails:
Trying to create too many point in time contexts. Must be less than or equal to: [300].
Examples
Two common query shapes trigger it:
- Explicit large limit:
source=logs-* | head 100000- the limit is pushed into the scan and exceeds the window, so a PIT is created and ten pages are fetched. - Unbounded scan:
source=logs-* | streamstats count() as seen- no explicit limit, so theplugins.query.size_limitcap sits above an operator it cannot be pushed through. The scan is left unbounded and a PIT is created, but only 10,000 rows are returned and no second page is ever requested, so the snapshot serves no purpose.
What solution would you like?
| Option | Approach | Pros | Cons | Notes |
|---|---|---|---|---|
| 1. Predicate-based index pruning | Narrow the wildcard to only the indices that can match, then open the PIT over that set. Snapshot semantics unchanged. | No consistency change. Smallest change. Works even for shapes that cannot avoid a PIT. | Reimplements pruning core already does, and misses core's ongoing work in this area. | Core could instead expose can_match, or new index/field-level stats, as an internal API. See opensearch-project/OpenSearch#21865, #22483, #22451. |
| 2. Incremental execution | Split the resolved index set into batches and scan batch by batch, opening and closing one PIT per batch. | Bounds context count regardless of how broad the pattern is. Complements option 1 when many indices still match after pruning. | Snapshot is per batch rather than global. More PIT create/delete calls and longer wall-clock time. | Could later extend to progressive result delivery, returning rows as each batch completes. |
| 3. Stateless pagination | Drop the PIT and page with a value-based search_after cursor. Each page is a plain search holding no server state. |
Nothing accumulates against the cap. Every page gets can_match and coordinator pruning automatically. |
No cross-page snapshot, so concurrent writes may cause missed or duplicated rows. Needs a stable, unique sort key, and none is both cheap and globally unique. | Known as keyset pagination. _shard_doc requires a PIT (opensearch-project/OpenSearch#18924); _seq_no is the closest alternative but is unique only per shard. Paginate docs |
| 4. Full pipeline pushdown | Compile the whole pipeline into one search so the cluster returns a finished result — no pagination, like aggregation queries today. | Removes the failure mode entirely. Fixes a far broader translation gap than this issue. | Largest effort. Feasibility unverified, and coverage can never be complete, so a fallback is still needed. | #3879 and #5646 are prior art for widening pushdown coverage. Scripted metrics are a possible escape hatch for pipelines with no aggregation equivalent. |
| 5. New search primitive | Add the missing primitive in core: a PIT scoped by predicate, or a search that owns its own pagination state. | Clean for every client, not just SQL/PPL. | A core contribution, so timeline and effort are unknown. | CreatePitRequest has no query body or can-match phase today, and no upstream proposal exists. opensearch-project/OpenSearch#22530 is a precedent for adding a can-match phase to an engine. |
What alternatives have you considered?
Mitigations and adjacent directions considered, none of which we treat as a fix:
| Alternative | Effect | Drawback |
|---|---|---|
Raise search.max_open_pit_context |
Query untouched; more contexts permitted. | Each context pins segment readers and blocks merged-segment deletion. |
Raise index.max_result_window and use from + size |
Avoids the PIT entirely. | Every matching shard then returns up to size top hits for coordinator-side reduction, a far larger memory spike than paged reads. |
Request fewer rows than max_result_window |
No PIT; the query succeeds immediately. | Truncates the input to downstream row-consuming operators, so results change. |
| Fewer primary shards for new indices | Cuts fan-out as indices roll over. | Only affects indices created afterwards, so it does not resolve an active failure. |
| Precompute with rollups or transforms | Removes the query shape entirely for recurring dashboards. | Only suits known, repeated queries, and adds a pipeline to maintain. |
| Offload to the async query path | Sidesteps coordinator limits for very large fetches. | Changes the interaction model to submit-and-poll; not a drop-in for dashboard traffic. |
Do you have any additional context?
Related work in this repo:
- [FEATURE] Avoid using PIT search for simple query #3879 avoided PIT for queries under
max_result_window— prior art for the pushdown direction. - [BUG] Non-pushdownable stats/eventstats silently forces a full-scan PIT and fails with an opaque error #5634, [BUG] PPL query failed with Trying to create too many Point In Time contexts. Must be less than or equal to: [300] #5220 are symptom reports of the same failure.
- Surface PIT-context exhaustion with an actionable error message #5631 surfaces the exhaustion with an actionable error message.
Activity
dai-chen commentedon Aug 25, 2026
Option 1 - Index Pruning Approaches
Example query — the shape that triggers this issue (
head 100000exceedsindex.max_result_window, so a PIT is opened over every shard of every index matchinglogs-*):Pushed-down filter, referred to below as
<FILTER>:{"bool":{"must":[ {"range":{"@timestamp":{"from":"2026-04-03T08:00:00.000Z","to":"2026-04-07T19:00:00.000Z","include_lower":true,"include_upper":true,"format":"date_time","boost":1.0}}}, {"match_phrase":{"body":{"query":"\"method\":\"POST\"","slop":0,"zero_terms_query":"NONE","boost":1.0}}} ],"adjust_pure_negative":true,"boost":1.0}}_field_caps+index_filterPOST logs-*/_field_caps?fields=@timestamp{index_filter:<FILTER>}indicesarray. Ref: https://docs.opensearch.org/latest/api-reference/search-apis/field-caps/#example-using-an-index-filter_indexterms agg probePOST logs-*/_search{size:0, track_total_hits:false, terminate_after:1, query:<FILTER>, aggs:{_idx:{terms:{field:"_index", size:4096}}}}size:0andterminate_aftertrim only the tail, not the setup. Andcan_matchruns only abovepre_filter_shard_size(default 128 shards) — below that, nothing is prunedsum_other_doc_count > 0for the 4096-bucket cap@timestampcachePOST /_msearchper index,{size:0, aggs:{mn:{min:{field:"@timestamp"}}, mx:{max:{...}}}}, noqueryqueryis what keeps it cheap)_search_shards+ queryPOST logs-*/_search_shards{query:<FILTER>}creation_dateGET /_cat/indices/logs-*?h=index&format=jsonindex_field_domainsoffIndexMetadata, behindsearch.index_pruning.enabledbool.filter/bool.muston configured fieldscan_match27 → 0.6 over 90 daily indicesIndexNameExpressionResolver.concreteIndexNames()+ routing tablesearch.max_open_pit_contextdai-chen commentedon Aug 26, 2026
Option 1 — Implementation Approaches [WIP]
Overview
When exploring the implementation approach for Option 1 index pruning, we also want to see whether it can mitigate the recently reported schema-conflict problem, not just PIT exhaustion. Either way, this rests on two explicit assumptions about the common time-series case:
search.max_open_pit_context.Approaches
The table below lists implementation options for the pruning step itself. All three share the same probe,
_field_capswithindex_filter. They differ only in where the partition predicate comes from — each time-bucketed index is effectively a partition — which in turn decides whether the schema half is reachable at all.where— no upstream or UI changeanalyze(); the only place a time predicate exists pre-scanPushDownContextatOpenSearchRequestBuilder.build()WHEREliteral but Lucene parses the probe, so a non-UTC session zone can make the plan-time bound narrower → silently drops indices; needs outward widening and ISO-only literals. Must discardOR/NOT/function-wrapped subtrees, needs boundary analysis foreval-redefined fields, and cannot attribute predicates across a join → single-relation pipelines onlyearliest=/latest=in the search command, already in PPL — local scope, matching Splunk's rule that an inline range "apply only to that portion of the search"TimeBoundstoRelationinAstBuilder.visitSearchFrom, prune inOpenSearchSchema.registerTablebefore the scan. No divergence risk: already normalized to OpenSearch date math, so the same parser evaluates both sidesquery_string, which has nodoRewriteyieldingMatchNoneQueryBuilder, socan_matchcannot prune on it. Must use the structuredTimeBoundsfor the probe, notsourceBuilderearliest=/latest=; hardcoded to@timestamp(OpenSearchConstants.IMPLICIT_FIELD_TIMESTAMP); primary source only, cross-source semantics undefined todaystart_time/end_timerequest parameters — global scope, as with ES|QL's request-levelfiltervsWHEREand Splunk's time range picker, which does propagate to subsearchesbuildFrameworkConfig, apply inregisterTableto every OpenSearch-backed table. No AST work, no visitor change, no ordering problemPseudocode
Approach 1 — extraction for schema, pushdown context for PIT (two mechanisms)
Approach 2 — bounds on the
Relation, one mechanismThe holder must be shared between
CalcitePlanContextand the per-queryOpenSearchSchema— both are created together inQueryService.buildFrameworkConfig, so construct one mutable holder there and hand it to both. The probe lives in theopensearchmodule because it needs anOpenSearchClient; a narrowSupportsIndexPruninginterface keepscorefree of OpenSearch types.Approach 3 — global external parameter (no AST work at all)
Suggested sequencing
The PIT fix is the same regardless of which schema approach is eventually chosen — always take the DSL filter already sitting in the scan's
PushDownContextand use it as theindex_filterfor_field_caps. It is independent of approaches 2 and 3.So the proposed order:
If both land, the overlap is harmless: a pre-scan prune from 2 or 3 narrows
indexNamefirst, and the pushdown-stage prune then operates on the already-narrowed expression, appending fewer or no additional exclusions.Send the bounds as the engine's own request parameters
Prune indices by request-level time bounds before the schema is resolved
Narrow only the outermost source
Use resolvable links in the review package