AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
docs(es-compat): make the published scroll escape hatch actually work (#370)
xerj-orga0b40f18bc1f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8b438d39c..f621ded1e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -39,12 +39,58 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0published number is checked against the server's behaviour rather thanagainst a second hand-written copy of it.- Verified against a node built from this branch (v1.0.0-rc.17, ES-compat- listener on :19370, 11,450 documents in `logs`): the scroll open returns- `400 illegal_argument_exception` naming `[11450]`, `[10000]` and- `[search_after]`; a 6,012-document subset scrolls normally and returns a- `_scroll_id`; and `search_after` on `_id` walks all 11,450 documents over 12- pages of 1,000.+ **The published escape hatch is now executed, not just spell-checked.** A+ pinned number is worth nothing if the recipe past it is wrong, and the first+ draft of this page's `search_after` transcript was: it paged with+ `search_after: ["999"]` against 11,450 numeric-looking `_id`s. `_id` is a+ keyword and sorts lexicographically, so `"1000" < "999"` and page 1 of 1,000+ actually ends at `_id` `"10897"`. Followed exactly as printed, including the+ page's own stop rule ("until a page comes back empty"), that walk collected+ 1,010 of 11,450 documents — 10,440 missing, every response a 200 — which is+ the silently-truncated export that #198 and this very page exist to rule out.+ The transcript now publishes the cursor the response actually returns, shows+ the hit it comes from, and states the lexicographic ordering that produced the+ mistake. `published_search_after_recipe_walks_the_whole_corpus` parses the+ transcript out of the page, seeds the corpus the transcript itself names,+ replays the printed request bodies verbatim against the real router, and+ asserts the walk collects every seeded `_id` over the page count the+ transcript claims — so a wrong cursor, an early stop, a repeated page or a+ drifted claim all fail the build.++ Three further scroll claims elsewhere in the tree were corrected to match:+ `landing/agent-search/index.html` said scroll *was* a deep-pagination cursor;+ `landing/llms-full.txt` §6 and `README.md` carried the bare "scroll is+ supported" form; and the ES→XERJ migration recipe in+ `docs/recipes/production-deployment.md` told readers they could point a+ whole-index scroll copy at a XERJ source with no mention of the ceiling.++ One boundary is documented rather than fixed here: the cap is applied to the+ request's summed total on `POST /{index}/_search?scroll=` (`es_compat.rs:14211`)+ but *per index* on the `POST /{index}/_search_scroll` alias+ (`es_compat.rs:19726`), so a multi-index scroll on that route can snapshot the+ ceiling from each index. That direction is permissive, not lossy. The pages now+ say so and point at+ [#405](https://github.com/xerj-org/xerj/issues/405), where the engine+ inconsistency is tracked.++ Verified by `cargo test -p xerj-api --test+ scroll_snapshot_cap_is_documented` — 3 passed in the `ci-test` profile+ (8.67s, overflow-checks off) and 3 passed in `dev` (12.40s, overflow-checks+ on). It drives `build_es_compat_router` over tempdir engines: an+ 11,450-document `logs` index+ refuses the scroll open with `400 illegal_argument_exception` naming `[11450]`+ and `[10000]`; a 128-document control scroll returns a `_scroll_id`; the+ printed first page returns 1,000 hits ending at `_id` `"10897"` with+ `sort: ["10897"]`; and the published walk from that cursor returns 11,450+ distinct `_id`s over 12 pages with none missing and none repeated. Reverting+ only the transcript hunk to the `["999"]` form fails the same test with+ `left: Array [String("999")] / right: Array [String("10897")]`, and with the+ cursor assertion inverted so the walk still runs, with "collected 1010 of+ 11450 documents over 2 pages, silently missing 10440". The `_search_scroll`+ divergence above was measured on two 6,000-document indices in one engine:+ `POST /sa,sb/_search?scroll=1m` → 400 naming `[12000]`/`[10000]`;+ `POST /sa,sb/_search_scroll?scroll=1m` → 200 with a `_scroll_id` and+ `hits.total {value: 12000, relation: "eq"}`.### Fixeddiff --git a/README.md b/README.mdindex ddac10d63..22db54e74 100644--- a/README.md+++ b/README.md@@ -222,7 +222,12 @@ Runnable examples live in [`recipes/`](./recipes) andXERJ implements the Elasticsearch REST API: indices, documents, bulk, search,aggregations, mappings, kNN, scroll, reindex and the `_cat` endpoints. Kibana and-the official client libraries connect to it directly.+the official client libraries connect to it directly. One boundary worth knowing+before you point export tooling at it: scroll is a bounded up-front snapshot, not+a segment-walking cursor, so a query whose exact total exceeds the snapshot+window is refused with a `400` rather than silently truncated — use+`search_after` for result sets of any size+([the cap](https://xerj.org/docs/api-es-compat.html#scroll-cap)).The conformance suite runs on every commit and currently passes **1366 of 1369**cases. It lives in [`engine/tests/es-compat-yaml`](./engine/tests/es-compat-yaml),diff --git a/docs/recipes/production-deployment.md b/docs/recipes/production-deployment.mdindex 829e92729..aaf2e10d7 100644--- a/docs/recipes/production-deployment.md+++ b/docs/recipes/production-deployment.md@@ -633,9 +633,19 @@ Notes for a real migration:overwrites rather than duplicates. For huge indices, checkpoint the last`_id`/offset and use `search_after` keyset paging instead of a long-livedscroll.-* **XERJ's scroll works too.** The same three calls (`_search?scroll=`,- `POST /_search/scroll`, `DELETE /_search/scroll`) are implemented on XERJ, so- you can point this script at a XERJ source for XERJ→XERJ copies as well.+* **XERJ's scroll works too — up to the snapshot cap.** The same three calls+ (`_search?scroll=`, `POST /_search/scroll`, `DELETE /_search/scroll`) are+ implemented on XERJ, so you can point this script at a XERJ source for+ XERJ→XERJ copies. But XERJ's scroll is a bounded up-front snapshot, not a+ segment-walking cursor: a query whose exact total exceeds the snapshot window+ is refused with a `400` naming the ceiling, rather than paged and silently+ truncated. Whole-index copies are normally over it, so for a XERJ source reach+ for the `search_after` keyset paging the previous bullet describes — take each+ cursor from the previous page's last `sort` value, and mind that `_id` sorts+ lexicographically (`"1000" < "999"`), so a cursor computed from the page+ number walks off into the wrong part of the sort order and ends the copy+ early with a 200. See+ [the cap](https://xerj.org/docs/api-es-compat.html#scroll-cap).---diff --git a/engine/crates/xerj-api/tests/scroll_snapshot_cap_is_documented.rs b/engine/crates/xerj-api/tests/scroll_snapshot_cap_is_documented.rsindex 044b4a540..49ae4e937 100644--- a/engine/crates/xerj-api/tests/scroll_snapshot_cap_is_documented.rs+++ b/engine/crates/xerj-api/tests/scroll_snapshot_cap_is_documented.rs@@ -16,7 +16,7 @@//! use `search_after` beyond that" is a different compatibility claim from//! "scroll is supported", and only the first one is true.//!-//! Two halves, and both are needed:+//! Three parts, and all three are needed://!//! 1. [`scroll_over_the_cap_is_refused_and_names_the_number`] drives the real//! ES-compat router over a corpus one document larger than the cap and@@ -28,10 +28,30 @@//! — the mechanism already used for the capability counts in//! `xerj-engine/tests/docs_capability_lists.rs`. Changing the constant now//! fails the build until the pages follow.+//! 3. [`published_search_after_recipe_walks_the_whole_corpus`] executes the+//! escape hatch the pages publish. It parses the `search_after` transcript+//! out of `landing/docs/api-es-compat.html`, seeds the corpus that+//! transcript names, replays the printed request bodies verbatim against+//! the real router, and checks that following the page's own stop rule+//! ("until a page comes back empty") really does collect every document,+//! over the page count the transcript claims.+//!+//! Part 3 exists because part 2 is not enough, and the gap is not academic:+//! the transcript first published here paged with `search_after: ["999"]`+//! against 11,450 numeric-looking `_id`s. `_id` is a keyword and sorts+//! LEXICOGRAPHICALLY, so `"1000" < "999"` and `"999"` sits near the *end* of+//! that corpus — the printed walk terminated after 1,010 of 11,450 documents,+//! with a 200 and an empty page, which is exactly the stop condition the page+//! states. Every published number was right, the cap was pinned, the walk+//! silently lost 91% of the export — on the page whose entire thesis is that+//! XERJ will not hand back a truncated export that looks complete (issue+//! #198). A recipe is only documented if it runs.//!//! The under-cap control in (1) exists so the test cannot pass vacuously: a//! tree where scroll 400s unconditionally would satisfy the over-cap assertion-//! and fail the control.+//! and fail the control. Part (3) cannot pass vacuously either: it asserts the+//! full set of seeded ids, so a walk that returns nothing, or stops early, or+//! repeats a page, fails.//!//! The alternative the refusal and the pages both name is not a XERJ//! invention. Lucene documents `IndexSearcher.searchAfter` as the way to do@@ -43,6 +63,18 @@//! That is why both the 400 and the docs insist on a *unique sort key*: the//! cursor is the sort tuple, so a non-unique one loses or repeats documents.//!+//! Lucene is equally explicit that a text sort key is ordered by bytes, not by+//! meaning: a binary/`SortField.Type#STRING` sort orders documents "by the+//! unsigned byte order of their sort key (`BytesRef#compareTo`)"+//! (`lucene/core/src/java/org/apache/lucene/search/BinarySortField.java:52-61`),+//! and getting *numeric* order out of that byte comparison takes a deliberate+//! encoding — `NumericUtils.intToSortableBytes` exists to "encode an integer+//! value such that unsigned byte order comparison is consistent with+//! `Integer#compare(int, int)`", flipping the sign bit to do it+//! (`lucene/core/src/java/org/apache/lucene/util/NumericUtils.java:178-188`).+//! Digits stored as text get no such encoding, which is the whole of why+//! `"1000" < "999"` and why the first transcript was wrong.+//!//! Lucene (Apache-2.0) is consulted for semantics only and no code from it is//! reproduced here. Elasticsearch likewise, and it is AGPL-3.0/SSPL-1.0///! Elastic-2.0 licensed.@@ -345,3 +377,282 @@ fn published_scroll_cap_matches_the_enforced_cap() {"expected at least one marked cap per page in {SCROLL_CAP_DOCS:?}, found {seen}");}++// ---------------------------------------------------------------------------+// 3. What the docs tell the user to *do*+// ---------------------------------------------------------------------------++/// The page carrying the `search_after` escape hatch, and the anchor of the+/// section that carries it.+const RECIPE_PAGE: &str = "landing/docs/api-es-compat.html";+const RECIPE_ANCHOR: &str = "id=\"scroll-cap\"";++/// The shell transcript in the scroll-cap section: the first+/// `<pre class="code">` block after the section's anchor.+fn scroll_cap_transcript(page: &str) -> &str {+ const OPEN: &str = "<pre class=\"code\">";+ const CLOSE: &str = "</pre>";+ let anchor = page+ .find(RECIPE_ANCHOR)+ .unwrap_or_else(|| panic!("{RECIPE_PAGE} has no `{RECIPE_ANCHOR}` section"));+ let rest = &page[anchor..];+ let from = rest+ .find(OPEN)+ .unwrap_or_else(|| panic!("{RECIPE_PAGE}: no `{OPEN}` transcript after {RECIPE_ANCHOR}"))+ + OPEN.len();+ let len = rest[from..]+ .find(CLOSE)+ .unwrap_or_else(|| panic!("{RECIPE_PAGE}: transcript after {RECIPE_ANCHOR} is unclosed"));+ &rest[from..from + len]+}++/// Every `-d '…'` request body in a shell transcript, in printed order.+///+/// Only a literal `-d '` opens a capture, so apostrophes in the surrounding+/// prose ("the last hit's `sort` value") and the quoted `-H` headers are not+/// mistaken for payload delimiters.+fn curl_payloads(block: &str) -> Vec<String> {+ const FLAG: &str = "-d '";+ let mut out = Vec::new();+ let mut rest = block;+ while let Some(at) = rest.find(FLAG) {+ let from = at + FLAG.len();+ let len = rest[from..]+ .find('\'')+ .unwrap_or_else(|| panic!("{RECIPE_PAGE}: unterminated `{FLAG}` payload"));+ out.push(rest[from..from + len].to_string());+ rest = &rest[from + len + 1..];+ }+ out+}++/// The transcript's own summary line: the `# → …` comment stating what the walk+/// above it produces, up to the end of that line.+///+/// Anchoring on the arrow rather than on "… pages" keeps the claim readings+/// below unambiguous no matter what the surrounding prose says.+fn claim_line(block: &str) -> &str {+ const ARROW: &str = "# → ";+ let at = block+ .find(ARROW)+ .unwrap_or_else(|| panic!("{RECIPE_PAGE}: transcript states no `{ARROW}` outcome"));+ let rest = &block[at + ARROW.len()..];+ rest.split('\n').next().unwrap_or(rest)+}++/// The digits (with optional `,` grouping) immediately preceding `needle`.+///+/// Lets the test read the transcript's own claims — "12 pages", "all 11,450+/// documents" — instead of restating them, so a transcript edited to claim+/// something else is checked against the new claim.+fn number_before(hay: &str, needle: &str) -> usize {+ let at = hay+ .find(needle)+ .unwrap_or_else(|| panic!("{RECIPE_PAGE}: transcript does not say `{needle}`: {hay}"));+ let head = hay[..at].trim_end();+ let start = head+ .rfind(|c: char| !c.is_ascii_digit() && c != ',')+ .map_or(0, |i| i + 1);+ head[start..].replace(',', "").parse().unwrap_or_else(|e| {+ panic!(+ "{RECIPE_PAGE}: `{}` before `{needle}` is not a number ({e})",+ &head[start..]+ )+ })+}++/// The number inside the first `open`…`]` after `open` (e.g. `too large: [`).+fn bracketed_after(hay: &str, open: &str) -> usize {+ let at = hay+ .find(open)+ .unwrap_or_else(|| panic!("{RECIPE_PAGE}: transcript does not contain `{open}`"))+ + open.len();+ let end = hay[at..]+ .find(']')+ .unwrap_or_else(|| panic!("{RECIPE_PAGE}: unterminated `{open}` bracket"))+ + at;+ hay[at..end]+ .replace(',', "")+ .parse()+ .unwrap_or_else(|e| panic!("{RECIPE_PAGE}: `{}` is not a number ({e})", &hay[at..end]))+}++async fn search(app: &axum::Router, index: &str, body: String) -> (StatusCode, Value) {+ send(+ app,+ Request::post(format!("/{index}/_search"))+ .header("content-type", "application/json")+ .body(Body::from(body))+ .expect("request"),+ )+ .await+}++/// The published `search_after` recipe, executed.+///+/// Issue #370 asked for the cap to be documented. The documentation is only+/// worth anything if the way *past* the cap, which is the one thing a reader+/// blocked by it will copy, actually works — so this replays it: the printed+/// bodies verbatim, the printed cursor verbatim, the page's own stop rule, and+/// the corpus the transcript itself names.+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]+async fn published_search_after_recipe_walks_the_whole_corpus() {+ let page = std::fs::read_to_string(repo_root().join(RECIPE_PAGE))+ .unwrap_or_else(|e| panic!("cannot read {RECIPE_PAGE}: {e}"));+ let transcript = scroll_cap_transcript(&page);++ // The transcript's own premise and its own claimed outcome.+ let corpus = bracketed_after(transcript, "too large: [");+ let claim = claim_line(transcript);+ let claimed_pages = number_before(claim, " pages");+ let claimed_docs = number_before(claim, " documents");+ assert!(+ corpus > SCROLL_SNAPSHOT_MAX_HITS,+ "the transcript's premise is a corpus over the cap, but it names {corpus} \+ against a cap of {SCROLL_SNAPSHOT_MAX_HITS}"+ );+ assert_eq!(+ claimed_docs, corpus,+ "the transcript refuses a scroll over {corpus} documents but then claims the \+ `search_after` walk returns {claimed_docs}; the two halves must describe the \+ same index or the recipe is not the escape hatch for the refusal above it"+ );++ // The printed request bodies. The refused-scroll example has no `sort`;+ // the two `search_after` pages do.+ let paged: Vec<String> = curl_payloads(transcript)+ .into_iter()+ .filter(|p| p.contains("\"sort\""))+ .collect();+ assert_eq!(+ paged.len(),+ 2,+ "expected exactly two sorted request bodies in the transcript (the first page \+ and one continuation); found {}: {paged:?}",+ paged.len()+ );+ let (first_body, next_body) = (&paged[0], &paged[1]);+ let first: Value = serde_json::from_str(first_body)+ .unwrap_or_else(|e| panic!("printed first page body is not JSON ({e}): {first_body}"));+ let next: Value = serde_json::from_str(next_body)+ .unwrap_or_else(|e| panic!("printed continuation body is not JSON ({e}): {next_body}"));+ assert!(+ first.get("search_after").is_none(),+ "the first printed page must open the walk, not continue one: {first_body}"+ );+ let printed_cursor = next+ .get("search_after")+ .unwrap_or_else(|| {+ panic!("the printed continuation carries no `search_after`: {next_body}")+ })+ .clone();+ assert_eq!(+ first.get("sort"),+ next.get("sort"),+ "the two printed pages sort differently, so the second cannot continue the \+ first: {first_body} then {next_body}"+ );++ // The corpus the transcript describes: `corpus` documents whose `_id`s are+ // the decimal integers, which is what makes the lexicographic trap live.+ let (app, _dir) = app_with_docs("logs", corpus).await;++ // Page 1, exactly as printed.+ let (status, page1) = search(&app, "logs", first_body.clone()).await;+ assert_eq!(status, StatusCode::OK, "printed first page failed: {page1}");+ let hits = page1["hits"]["hits"]+ .as_array()+ .unwrap_or_else(|| panic!("printed first page returned no hits array: {page1}"))+ .clone();+ assert!(+ !hits.is_empty(),+ "printed first page returned zero hits over a {corpus}-document index: {page1}"+ );++ // The cursor the reader is told to use is the previous page's last `sort`.+ // If the printed one is not that value, the printed walk starts somewhere+ // else in the sort order — which is how a keyset export silently drops+ // documents while still returning 200s.+ let real_cursor = hits+ .last()+ .and_then(|h| h.get("sort"))+ .unwrap_or_else(|| panic!("hits carry no `sort` values to page on: {page1}"))+ .clone();+ assert_eq!(+ printed_cursor,+ real_cursor,+ "the transcript continues with search_after={printed_cursor} but page 1 of the \+ corpus it describes ends at search_after={real_cursor} (last _id {}). `_id` is \+ a keyword and sorts lexicographically, so a cursor guessed from the page size \+ lands in the wrong place and the walk ends early with a 200 and an empty page. \+ Publish the cursor the response actually returns.",+ hits.last().map(|h| h["_id"].clone()).unwrap_or(Value::Null)+ );++ // Now walk it: printed continuation first, then the page's own rule —+ // "feed the last hit's `sort` value back as `search_after` until a page+ // comes back empty".+ let mut seen: std::collections::HashSet<String> = hits+ .iter()+ .map(|h| h["_id"].as_str().expect("_id").to_string())+ .collect();+ let mut returned = hits.len();+ let mut pages = 1usize;+ let mut body = next_body.clone();+ let ceiling = claimed_pages * 4 + 16;+ loop {+ let (status, resp) = search(&app, "logs", body.clone()).await;+ assert_eq!(status, StatusCode::OK, "page {} failed: {resp}", pages + 1);+ let page_hits = resp["hits"]["hits"]+ .as_array()+ .unwrap_or_else(|| panic!("page {} returned no hits array: {resp}", pages + 1))+ .clone();+ if page_hits.is_empty() {+ break;+ }+ pages += 1;+ returned += page_hits.len();+ for hit in &page_hits {+ seen.insert(hit["_id"].as_str().expect("_id").to_string());+ }+ assert!(+ pages <= ceiling,+ "the published walk did not terminate within {ceiling} pages; the \+ transcript claims {claimed_pages}"+ );+ let cursor = page_hits+ .last()+ .and_then(|h| h.get("sort"))+ .unwrap_or_else(|| panic!("page {pages} carries no `sort` to continue from: {resp}"))+ .clone();+ let mut cont = next.clone();+ cont["search_after"] = cursor;+ body = cont.to_string();+ }++ assert_eq!(+ returned,+ seen.len(),+ "the published walk returned {returned} hits but only {} distinct ids — a \+ keyset walk that repeats documents is as wrong as one that skips them",+ seen.len()+ );+ let missing: Vec<String> = (0..corpus)+ .map(|n| n.to_string())+ .filter(|id| !seen.contains(id))+ .collect();+ assert!(+ missing.is_empty(),+ "following the published recipe exactly — including its own stop rule — \+ collected {} of {corpus} documents over {pages} pages, silently missing {} \+ (first few: {:?}). This is the truncated-export failure the scroll 400 above \+ it exists to prevent, reintroduced in the remediation for it.",+ seen.len(),+ missing.len(),+ &missing[..missing.len().min(5)]+ );+ assert_eq!(+ pages, claimed_pages,+ "the transcript claims the walk takes {claimed_pages} pages; it took {pages}"+ );+}diff --git a/landing/agent-search/index.html b/landing/agent-search/index.htmlindex 252be3c0e..f11192dcf 100644--- a/landing/agent-search/index.html+++ b/landing/agent-search/index.html@@ -346,7 +346,7 @@ curl -X POST localhost:9200/kb/_search -H 'Content-Type: application/json' -d '{{ id:"chunking", title:"Auto-chunk long documents",text:"Split long passages into overlapping chunks and embed each chunk, then retrieve the single best-matching passage instead of a whole document." },{ id:"paginate", title:"Sort and paginate results",- text:"Order hits by score or by a field value, and page through them with from and size. Deep pagination uses search_after or a scroll cursor." },+ text:"Order hits by score or by a field value, and page through them with from and size. Deep pagination uses search_after on a unique sort key; scroll is a bounded snapshot, not a cursor." },{ id:"security", title:"Secure the cluster with TLS and keys",text:"Protect XERJ with TLS encryption and API-key authentication. Tokens gate every request; the insecure flag disables both for local development only." }];diff --git a/landing/docs/api-es-compat.html b/landing/docs/api-es-compat.htmlindex 42a43c293..33c372a78 100644--- a/landing/docs/api-es-compat.html+++ b/landing/docs/api-es-compat.html@@ -193,6 +193,8 @@<p>This is the common case, not the corner case: <code class="inline">helpers.scan()</code> in <code class="inline">elasticsearch-py</code>, reindex internals, and most export and backup tooling all scroll a whole index, and whole indices are usually bigger than the cap.</p>+ <p>The ceiling above is the one <code class="inline">_search?scroll=</code> enforces, on the request's total across every index it resolves. One route is looser: the <code class="inline">POST /:index/_search_scroll</code> alias applies the ceiling <em>per index</em>, so a comma-separated multi-index scroll sent there can snapshot the full ceiling from each. That direction is permissive, not lossy — every matched document is still in the snapshot and still paged out — but it means the number is a per-index ceiling on that one route. Tracked in <a href="https://github.com/xerj-org/xerj/issues/405">#405</a>.</p>+<pre class="code"># 11,450 documents in `logs` — over the cap, so the scroll never opens$ curl -sX POST 'http://localhost:9200/logs/_search?scroll=1m' \-H 'Content-Type: application/json' \@@ -208,9 +210,19 @@ sort key instead, or narrow the query."}], ... },"status":400}$ curl -sX POST http://localhost:9200/logs/_search \-H 'Content-Type: application/json' \-d '{"size":1000,"sort":[{"_id":"asc"}],"query":{"match_all":{}}}'+{"hits":{"hits":[ ...,+ {"_index":"logs","_id":"10897","_score":null,"_source":{"n":10897},"sort":["10897"]}]}}++# the cursor is that last hit's `sort` array, copied verbatim. Read it out of+# the response; never guess it from the page number. `_id` is a keyword, so it+# sorts LEXICOGRAPHICALLY — "1000" < "999" — and page 1 of numeric-looking ids+# ends at "10897", not "999". Pass ["999"] here and the walk ends after+# 1,010 of the 11,450 documents, with no error — the silent truncation this+# whole page exists to rule out. Sort on a numeric field, or on a keyword+# whose text order is the order you actually want.$ curl -sX POST http://localhost:9200/logs/_search \-H 'Content-Type: application/json' \- -d '{"size":1000,"sort":[{"_id":"asc"}],"search_after":["999"],"query":{"match_all":{}}}'+ -d '{"size":1000,"sort":[{"_id":"asc"}],"search_after":["10897"],"query":{"match_all":{}}}'# → 12 pages, all 11,450 documents, no ceiling</pre><h2>Bulk indexing example</h2>diff --git a/landing/docs/migration-from-es.html b/landing/docs/migration-from-es.htmlindex 48b5d696b..3072dde45 100644--- a/landing/docs/migration-from-es.html+++ b/landing/docs/migration-from-es.html@@ -134,7 +134,7 @@<h2>What needs rewriting</h2><ul>- <li><strong>Whole-index scroll reads.</strong> <!-- generated:scroll-snapshot-cap -->10,000<!-- /generated:scroll-snapshot-cap --> documents is the hard ceiling on a scroll: XERJ materialises the snapshot up front, so a query whose exact total is larger is refused with a <code class="inline">400</code> rather than paged and silently truncated. Anything that scrolls an entire index — <code class="inline">helpers.scan()</code>, exports, reindex scripts — moves to <code class="inline">search_after</code> on a unique sort key, which is unbounded. Details on the <a href="/docs/api-es-compat.html#scroll-cap">ES-compat API</a> page.</li>+ <li><strong>Whole-index scroll reads.</strong> <!-- generated:scroll-snapshot-cap -->10,000<!-- /generated:scroll-snapshot-cap --> documents is the ceiling on a <code class="inline">_search?scroll=</code> snapshot: XERJ materialises the snapshot up front, so a query whose exact total is larger is refused with a <code class="inline">400</code> rather than paged and silently truncated. Anything that scrolls an entire index — <code class="inline">helpers.scan()</code>, exports, reindex scripts — moves to <code class="inline">search_after</code> on a unique sort key, which is unbounded. Mind that <code class="inline">_id</code> sorts lexicographically; take each cursor from the previous page's last <code class="inline">sort</code> value rather than computing it. Details, and the one route that applies the ceiling per index instead, on the <a href="/docs/api-es-compat.html#scroll-cap">ES-compat API</a> page.</li><li><strong>Scripted fields / scripted metrics.</strong> Painless is not implemented. Use <code class="inline">function_score</code> for the cases it covers.</li><li><strong>Runtime fields.</strong> Not supported. Compute at ingest or query time.</li><li><strong>Cross-cluster search.</strong> Single-cluster only in v0.1.</li>diff --git a/landing/llms-full.txt b/landing/llms-full.txtindex e7ca2080a..0c13695d3 100644--- a/landing/llms-full.txt+++ b/landing/llms-full.txt@@ -153,6 +153,16 @@ Content types:and export scripts) reads whole indices, and whole indices are usually larger than thecap. So the accurate compatibility claim is "scroll is supported, with a boundedsnapshot cap; use `search_after` beyond that", NOT "scroll is supported".+ Two things to get right when you switch. (a) The cursor is the previous page's LAST hit's+ `sort` array, copied verbatim out of the response — never a value you computed from the+ page number. `_id` is a keyword and sorts LEXICOGRAPHICALLY ("1000" < "999"), so over+ 11,450 numeric-looking ids page 1 of 1,000 ends at "10897"; passing ["999"] instead walks+ off the end of the corpus and returns an empty page after 1,010 documents, with no error.+ Sort on a numeric field if you want numeric order. (b) The ceiling above is what+ `_search?scroll=` enforces, against the request's total over every index it resolves. The+ `POST /{index}/_search_scroll` alias applies it PER INDEX instead, so a multi-index scroll+ sent there can snapshot the full ceiling from each — permissive, not lossy; nothing is+ truncated. Tracked in https://github.com/xerj-org/xerj/issues/405.- Default `_search` source is compact. When `_source` is omitted, ordinary source fieldsare returned but engine-generated `<field>_vector` and `<field>_vector_chunks` companions@@ -731,7 +741,8 @@ parent/child join, so running these would return silently wrong hits:Any other query type answers `unknown query type`.Search body options: from, size, sort, _source (include/exclude), highlight, aggs,-track_total_hits, and (via dedicated endpoints) scroll and point-in-time.+track_total_hits, and (via dedicated endpoints) scroll and point-in-time. Scroll is a+bounded snapshot, not a cursor — see the cap in §2; `search_after` is the unbounded path.Aggregations (complete; no probabilistic sketch in the metric path — cardinalityis a true distinct count, not an HLL estimate, and terms doc_count is precise).