What this thread does
Do first: open POST /my-index/_pit?keep_alive=1m, then paginate with unchanged query and sort plus the complete last hit's sort array in search_after.
Short answer
As of November 2026, Elasticsearch 9.5.7 is the release baseline; behavior below follows current pagination/PIT references. A PIT freezes the search view; its implicit _shard_doc tie-breaker is constant within a PIT. Keep the newest PIT ID and renew its lease on each request (pagination).
Choose / don't choose
- PIT plus search_after: choose for sequential traversal beyond the result window or a stable browse session; don't promise arbitrary page-number jumps.
- Shallow offsets: choose when the requested window fits the index limit; don't raise that limit to hide a growing memory-intensive offset scan (index setting).
- Long-lived snapshot: choose only with an explicit session expiry policy; retained segments consume resources, so close abandoned sessions (PIT lifetime).
Not for: choosing a search engine; see meilisearch-typesense-or-postgres-full-text-search-for-my-app-2026.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
sort | Fixed ordered field list; PIT adds an implicit sort tiebreaker field called _shard_doc, which can also be provided explicitly | Current Elasticsearch docs, November 2026 | pagination |
search_after | Omit on first page; afterward take the sort values from the last hit, and insert those into the search_after array | PIT pagination | pagination |
pit.id | Latest returned PIT ID, not permanently the ID from opening | PIT pagination | pagination |
pit.keep_alive | "1m" is the documented example, not a universal default; choose longer than the expected next-request delay and extend its time to live with search requests | PIT search | pagination |
size | Application choice, e.g. 1000; keep each page bounded by the configured result window and memory budget | Ordinary search_after requests | window |
index.max_result_window | Default 10000, limits from + size; deep cursors avoid accumulating from, not unbounded page sizes | Elasticsearch index setting | setting |
Order of operations
1. Open a PIT on the target index. A subsequent search request with pit must not specify index; routing/preferences are inherited from the PIT (open API). 2. First request has the fixed query/sort and no cursor. On each successful page, use the latest PIT ID and the entire final hit's sort array. Do not derive a cursor from only the timestamp or _id (pagination). 3. Send the next page using that newest pit.id, unchanged query/sort, and search_after. Keep from at zero or omit it. Extend keep_alive sufficiently to cover the next request; it need not cover the whole traversal (pagination). 4. Continue until no hits remain. Close the PIT with DELETE /_pit and its id in the body, including cancellation/error cleanup when the context is still available (pagination). 5. On expiration or missing search context, invalidate the cursor. Open a fresh PIT and restart from page one with a visible new-session boundary. This recovery policy follows from the PIT-specific tie-breaker: never combine a new snapshot with an old _shard_doc cursor. If a product needs resumable export, design a separate durable checkpoint contract.
Known failures and fixes
Diagnostic: search_context_missing_exception
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
search_context_missing_exception | Context is unavailable; expiry is one possible cause, not the only one | Discard the cursor/PIT pair and restart explicitly. Investigate context loss if it occurs before the lease ends | harshvikramsingh, November 29, 2023, PIT lifetime |
NoShardAvailableActionException | A PIT contains unavailable shards | Restore shard availability and create a new PIT; restart pagination instead of reusing the old PIT's sort tuple | PIT API |
The dated expired-PIT question describes a user returning after a long pause; harshvikramsingh's separate report describes context loss despite timely requests. Increasing retention alone cannot resolve every missing-context report.
Missing
- A new PIT cannot restore the expired snapshot. Exactly-once traversal across snapshot loss requires an application recovery model, not silent cursor reuse.
Checked
2026-11-12; Elasticsearch 9.5.6 release, current pagination/PIT/index-setting references and dated expiry/context-loss reports read. No cluster requests executed.
Started from a post by @Elastic, packaged by the editor. Original post