8000 fix(es-compat): apply alias filters on _msearch (#451 class C) by xerj-org · Pull Request #559 · xerj-org/xerj · GitHub
[go: up one dir, main page]

Skip to content

fix(es-compat): apply alias filters on _msearch (#451 class C) - #559

Merged
xerj-org merged 4 commits into
mainfrom
fix/451c-alias-filter-reads
Aug 21, 2026
Merged

xerj-org merged 4 commits into
mainfrom
fix/451c-alias-filter-reads

Conversation

@xerj-org
Copy link
Copy Markdown
Owner

Advances #451 (does not close it — see Scope). Fixes the _msearch half of failure class C: a filtered alias's document boundary was bypassed.

The defect (class C)

msearch_impl resolved an alias to its members via resolve_alias and searched them directly, never reading index_alias_metadata — so an alias's filter was dropped. A filtered alias is the standard poor-man's document-level boundary, so _msearch returned document bodies the alias exists to hide, while _search through the same alias honours the filter.

Reproduced: a filtered alias (filter: status=active) over an index with one active + one archived doc — _search → 1 hit; _msearch → 2 hits (the archived out-of-slice doc leaked).

The fix

AND the alias filter into each sub-search body before parsing, mirroring the existing pit.index_filter injection a few lines above (same bool{must:[query], filter:[…]} merge) and the exact filter-gathering search_impl / resolve_by_query_targets use (keyed on the written alias name). Fail-before 2 → now 1.

Scope / why #451 stays open

Fixes _msearch. search_with_scroll, msearch_template, and _cat/count share the same class-C gap (they resolve via resolve_alias and don't read index_alias_metadata) — those follow separately. (The class-B get_index read endpoints were fixed in #555; eql_search fan-out remains the #395/#451 dispatch decision.)

Verification (rustc 1.98.0)

Full xerj-api suite 473 passed, 0 failed; fmt --check, clippy --workspace --all-targets -D warnings clean. New repro test included.

@cla-bot cla-bot Bot added the cla-signed label Aug 21, 2026
8000
@xerj-org
Copy link
Copy Markdown
Owner Author

Scope update: added a reproduce-first check of search_with_scroll — despite the issue's static analysis, a scroll opened through a filtered alias already returns only the in-slice slice (the initial scroll search delegates through the filter-applying path). Committed as a passing, non-vacuous regression guard (a leak would make total=2). So this PR: _msearch = fixed, scroll = confirmed-safe + guarded. Remaining class-C to check: msearch_template and _cat/count.

msearch_impl resolved an alias to its members and searched them directly, never
reading index_alias_metadata, so a filtered alias -- the standard poor-man's
document boundary -- leaked the documents it exists to hide (_search through the
same alias honours the filter). AND the alias filter into each sub-search body
before parsing, mirroring the existing pit.index_filter injection and the
search_impl / resolve_by_query_targets filter-gathering.

Fail-before: _msearch through a filtered alias returned 2 hits (active + archived)
vs 1 for _search; now 1. Repro test added.

Scope: fixes _msearch. search_with_scroll / msearch_template / _cat/count share
the same class-C gap and follow separately.
…ss C)

Reproduce-first check of search_with_scroll: despite the issue's static analysis
(0 index_alias_metadata refs), a scroll opened through a filtered alias already
returns only the in-slice slice — the initial scroll search delegates through the
filter-applying path. Added as a passing, non-vacuous guard (a leak would make
total=2). So only _msearch needed the fix in this PR; scroll is confirmed safe.
cat_count summed stats().doc_count per member, ignoring any alias filter, so a
filtered alias reported a count including the out-of-slice documents it exists to
hide. When the alias is filtered, count only the filter-admitted docs (size:0
filtered search per member); the fast doc_count path is unchanged when unfiltered.

Fail-before: _cat/count through a filtered alias returned count=2 (active+archived)
vs the 1-doc slice; now 1. Repro test added.

This PR now covers class C: _msearch (fixed) + _cat/count (fixed) + scroll (guarded,
already safe). Remaining: msearch_template.
…tes #451 class C

msearch_template_impl ran the rendered template search against the alias members
without reading index_alias_metadata, leaking the out-of-slice docs a filtered
alias hides. AND the alias filter into the rendered body before parsing, mirroring
the _msearch fix. Fail-before: total=2 vs the 1-doc slice; now 1.

Class C is now complete: _msearch, _cat/count, _msearch/template all honour a
filtered alias, and scroll (already safe) is guarded. Repro test for each.
@xerj-org
Copy link
Copy Markdown
Owner Author

Scope update: #451 class C is now complete in this PR. Reproduce-first confirmed and fixed all leaking sites — _msearch, _cat/count, and _msearch/template now honour a filtered alias's document boundary; search_with_scroll was already safe and is guarded. Each has a fail-before→pass repro. All 4 tests green under 1.98.0; fmt/clippy clean.

@xerj-org
Copy link
Copy Markdown
Owner Author

Independent 3-skeptic verification (each REFUTES, own worktree, rustc 1.98.0)

Verdict: 0 BLOCKING — correctness=nit, regression-risk=nit, evidence-holds=none.

correctness (nit): All three sites AND the alias filter correctly — msearch_impl/msearch_template_impl gather from the written alias name and merge into the body before parse (bool{must:[q],filter:[…]}), keyed exactly like search_impl; idx.search per member so no double-application. cat_count keeps the fast stats().doc_count path when unfiltered and only runs a filtered size:0 count for a filtered alias. Nit: a mixed selector hot,idx-b (filtered alias + plain index) applies hot's filter across idx-b too — but this mirrors existing search_impl/_count behavior, not a new regression.

regression-risk (nit): Full cargo test -p xerj-api — 477 passed, 0 failed, 47 suites; clippy clean. Every change is gated behind if !alias_filters.is_empty(), so plain-index/unfiltered paths are byte-for-byte unchanged. Non-blocking caveats: (1) the mixed-selector over-filter above; (2) cat_count contributes 0 for a member if parse_request/search errors — an undercount (safe direction for a filter, filtered-alias only), vs the old over-count.

evidence-holds (none): Mutation-verified — neutralizing the msearch / msearch_template / cat_count injections each makes its test fail (leak/over-count 2 vs 1); the scroll test passes independently (a genuine non-vacuous guard confirming _search?scroll= already applies the filter via search_impl — honest "already-safe" scoping). Nit: the PR prose credits search_with_scroll, but the _search?scroll= test dispatches to search_impl.

Gate: checks green, 0 BLOCKING, CLEAN. Merging; nits filed as follow-up.

@xerj-org
xerj-org merged commit 1fcca5e into main Aug 21, 2026
18 checks passed
buger pushed a commit to probelabs/xerj that referenced this pull request Aug 22, 2026
…ndercounting (xerj-org#563)

The filtered-alias branch of `_cat/count` counted each member via
`if let Ok(idx) … if let Ok(req) … if let Ok(res) { count += res.total.value }`.
Any per-member `get_index` / `parse_request` / `search` error made that member
silently contribute 0 — a plausible-looking UNDERCOUNT with a 200 and no signal
(the safe direction over the old `stats().doc_count` over-count xerj-org#559 replaced,
but still a wrong number). Propagate the error, like the scroll fan-out above
already does, so the caller gets a loud error rather than a quiet undercount.

The `Ok` path is byte-identical, so the existing
`filtered_alias_filter_applies_on_msearch` `_cat/count` guard is unaffected.

Verification (rustc 1.98.0): clippy --workspace --all-targets -D warnings clean,
full xerj-api suite green. The error path is not triggerable through the public
API, so this is a defensive hardening verified by inspection + suite-green, not a
runtime fail-before test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0