Repository navigation
fix(es-compat): apply alias filters on _msearch (#451 class C) - #559
Conversation
|
Scope update: added a reproduce-first check of |
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.
|
Scope update: #451 class C is now complete in this PR. Reproduce-first confirmed and fixed all leaking sites — |
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 — regression-risk (nit): Full 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 Gate: checks green, 0 BLOCKING, CLEAN. Merging; nits filed as follow-up. |
…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.
Advances #451 (does not close it — see Scope). Fixes the
_msearchhalf of failure class C: a filtered alias's document boundary was bypassed.The defect (class C)
msearch_implresolved an alias to its members viaresolve_aliasand searched them directly, never readingindex_alias_metadata— so an alias'sfilterwas dropped. A filtered alias is the standard poor-man's document-level boundary, so_msearchreturned document bodies the alias exists to hide, while_searchthrough 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
filterinto each sub-search body before parsing, mirroring the existingpit.index_filterinjection a few lines above (samebool{must:[query], filter:[…]}merge) and the exact filter-gatheringsearch_impl/resolve_by_query_targetsuse (keyed on the written alias name). Fail-before2→ now1.Scope / why #451 stays open
Fixes
_msearch.search_with_scroll,msearch_template, and_cat/countshare the same class-C gap (they resolve viaresolve_aliasand don't readindex_alias_metadata) — those follow separately. (The class-Bget_indexread endpoints were fixed in #555;eql_searchfan-out remains the #395/#451 dispatch decision.)Verification (rustc 1.98.0)
Full
xerj-apisuite 473 passed, 0 failed;fmt --check,clippy --workspace --all-targets -D warningsclean. New repro test included.