Skip to content

armgit / xerj

Public Imported from GitHub
0

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.

docs: bring the `index: false` claims back to what the code does

xerj-org778422a38ed0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5c38f4ab1..46380a773 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,23 +26,49 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
sentence, `Cannot search on field [f] since it is not indexed nor has doc
values.`, as a 400 `search_phase_execution_exception` /
`query_shard_exception`. The check lives in one place — `search_inner` — and
- `_search`, `_count`, `_msearch` and `_explain` were each measured carrying it
- all the way to the wire: `_explain` answers the 400 instead of a confident
- `"matched": false` for a query it never ran, and `_msearch` renders it as a
- per-response 400 envelope with `type` and `root_cause` instead of a bare 500.
+ these surfaces were each measured reporting the rejection rather than
+ absorbing it, including the three that were swallowing it: `_search`,
+ `_count` on all four selectors (single index, `logs-*`, a comma list and the
+ cluster-wide `POST /_count`), `_msearch`, `_msearch/template`, `_explain`,
+ `_delete_by_query` and `_rank_eval`. `_explain` answers the 400 instead of a
+ confident `"matched": false` for a query it never ran; `_msearch` and
+ `_msearch/template` render it as a per-response 400 envelope with `type` and
+ `root_cause`, leaving the sibling sub-requests in the batch untouched; and
+ `_rank_eval` records the refused request under `failures` instead of dropping
+ it from `details` *and* `failures` while still publishing a `metric_score`.
+
+ A multi-index `_count` follows ES's broadcast rule rather than failing
+ outright: the failure status is returned only when **no** index answered
+ (`RestStatus.status`, semantics only), so `/t/_count` and a `logs-*` whose
+ indices all carry the offending mapping both 400 exactly as `_search` does,
+ while a mixed selector returns 200 with the partial count and the refusal
+ visible as `_shards.failed: 1` plus a `_shards.failures` entry carrying the
+ `query_shard_exception`. What it will not do any more is what it did before:
+ report `count: 0` with `"successful": 2, "failed": 0`.
+
`exists` is unaffected and still returns zero hits rather than an error, which
is also what ES does.
The multi-field query types follow ES's own split rather than a blanket rule.
An explicitly *named* field is rejected like any other named field —
- `multi_match` / `simple_query_string` with `"fields": ["note"]`, `query_string`
- with `"default_field": "note"` — while a *wildcard* spec such as
- `"fields": ["*"]` is never an error and goes on being answered exactly as
- before, because ES expands a pattern over the searchable fields and silently
- drops the rest (`QueryParserHelper.resolveMappingField`). Before this,
- the same user intent got two different answers: the `simple_query_string` form
- was rejected (the parser lowers it to a `match`) while the `multi_match` form
- returned the document through the unsearchable field.
+ `multi_match` / `simple_query_string` / `query_string` with
+ `"fields": ["note"]`, and `query_string` with `"default_field": "note"` —
+ while a *wildcard* spec such as `"fields": ["*"]` is never an error, because
+ ES expands a pattern over the searchable fields and silently drops the rest
+ (`QueryParserHelper.resolveMappingField`). Before this, the same user intent
+ got two different answers: the `simple_query_string` form was rejected (the
+ parser lowers it to a `match`) while the `multi_match` form returned the
+ document through the unsearchable field.
+
+ Reaching the `query_string` half of that meant fixing a second
+ accepted-and-ignored key in the same family: **`query_string`'s `fields`
+ array was never read by the parser**, so `{"query":"x","fields":["title"]}`
+ searched every field, and — once `index: false` became a real rejection —
+ disagreed with `{"default_field":"title"}`, which is the same request written
+ the other way. `fields` now selects the targets for a clause that named no
+ field of its own (a `dis_max` over one leaf per field when there is more than
+ one, `^boost` honoured) — the same job `simple_query_string`'s `fields` list
+ was already doing. A clause that does name its own field keeps it, as in ES.
The field is dropped from the full-text index at flush and merge only where
the stored-doc fallback is *equivalent* — a non-indexed `text` field. An
@@ -65,8 +91,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
**no** field is named: `query_string {"query":"…"}` and `more_like_this` with
no `fields` both still return the document. (Their *named* forms are
rejected — `more_like_this` with `fields` lowers to a `bool.should` of
- `match` at parse time and inherits the check.) Both gaps are pinned by
- assertions in
+ `match` at parse time and inherits the check.) **A wildcard `fields` spec
+ reaches that same field-less arm**: `simple_query_string` / `query_string`
+ with `"fields": ["*"]` lowers to the `"*"` placeholder and is answered by the
+ schema-free scan, so it can still match through an unsearchable field. It is
+ never an *error*, which is ES's rule and deliberate — but it is not "answered
+ over the searchable fields" either, and that is a pre-existing property of
+ wildcard expansion, identical on `main`. (`multi_match` with a pattern is
+ different: it is answered by the FTS projection, which does apply
+ `isSearchable()`, and finds nothing in an unsearchable field.) **The opaque
+ `query_string` fallback still ignores a multi-field `fields` list**: a query
+ string the parser declines to lower keeps the whole string for the FTS path,
+ where a one-element `fields` is carried across as `default_field` and a
+ longer list has nowhere to go. And **`_validate/query` never opens the
+ index** — it answers from the parse alone, so it reports `{"valid": true}`
+ for a body `_search` refuses. That too is unchanged from `main`, but it now
+ disagrees with `_search`, so it is written down rather than left to be
+ discovered. Every one of these gaps is pinned by an assertion in
`index_false_is_honoured::documented_gaps_are_still_open_and_still_documented`,
so closing one fails the test that says it is open.
diff --git a/engine/crates/xerj-engine/src/index.rs b/engine/crates/xerj-engine/src/index.rs
index de0cc8a64..104f00c6e 100644
--- a/engine/crates/xerj-engine/src/index.rs
+++ b/engine/crates/xerj-engine/src/index.rs
@@ -26932,14 +26932,24 @@ fn declared_field<'a>(schema: &'a Schema, field: &str) -> Option<&'a FieldConfig
/// are not searchable (`acceptAllTypes = isSimpleMatchPattern(spec) == false`
/// in `server/src/main/java/org/elasticsearch/index/search/QueryParserHelper.java:115-150`,
/// read for semantics only — ES is AGPL/SSPL/Elastic-2.0 and no code from it
-/// is reproduced here). So `fields: ["note"]` is rejected exactly like
-/// `match` on `note`, and `fields: ["*"]` keeps working over the searchable
-/// fields. Without this, the same user intent got two different answers:
-/// `simple_query_string {"fields":["note"]}` and `query_string
-/// {"default_field":"note"}` already 400ed because the parser lowers a
-/// single-field form to `Match`, while `multi_match {"fields":["note"]}` —
-/// and either of those with two fields — returned the document *through* the
-/// unsearchable field.
+/// is reproduced here). So a named `fields: ["note"]` is rejected exactly like
+/// `match` on `note`, and a pattern spec is never an error. Without this, the
+/// same user intent got two different answers: `simple_query_string
+/// {"fields":["note"]}` and `query_string {"default_field":"note"}` already
+/// 400ed because the parser lowers a single-field form to `Match`, while
+/// `multi_match {"fields":["note"]}` — and either of those with two fields —
+/// returned the document *through* the unsearchable field.
+///
+/// `query_string`'s `fields` array reaches these arms only because the parser
+/// now reads it (`parser::parse_query_string`); until then the key was
+/// accepted and ignored, so `{"fields":["note"]}` searched everything and
+/// disagreed with `{"default_field":"note"}`. An unqualified clause is now
+/// lowered onto those fields (a `dis_max` when there is more than one), which
+/// is what brings it here. One residue is left, and is not claimed shut: a
+/// query string this parser declines to lower (an unterminated quote, say)
+/// falls back to the opaque `QueryString` node, where a one-element `fields`
+/// is carried across as `default_field` and a longer list is not represented
+/// at all.
///
/// `more_like_this` needs no arm here: with an explicit `fields` list the
/// parser lowers it to a `bool.should` of `match` clauses, which the leaf arms
@@ -26948,13 +26958,17 @@ fn declared_field<'a>(schema: &'a Schema, field: &str) -> Option<&'a FieldConfig
/// gap below.
///
/// One gap remains open here, stated rather than papered over. The FTS route
-/// for these queries no longer projects a clause onto an unsearchable field
+/// no longer projects a clause onto an unsearchable field
/// (`text_fields`/`exact_fields` in `search_inner` apply ES's `isSearchable()`
-/// rule), but the stored-doc scan's FIELD-LESS arms are schema-free: they walk
-/// every non-`_` key of `_source`, so a token living only in an unsearchable
-/// field still matches when no field is named at all — `query_string
-/// {"query": "…"}` and a `more_like_this` with no `fields` both still return
-/// the document. Measured, not assumed. That divergence from the FTS
+/// rule — measured: `multi_match {"fields":["*","body"]}` finds nothing in an
+/// unsearchable `note`), but the stored-doc scan's FIELD-LESS arms are
+/// schema-free: they walk every non-`_` key of `_source`, so a token living
+/// only in an unsearchable field still matches when no field is named at all.
+/// `query_string {"query": "…"}` and a `more_like_this` with no `fields` both
+/// still return the document — and so does a *wildcard* spec in
+/// `query_string` / `simple_query_string`, because `fields: ["*"]` lowers to
+/// that same field-less `"*"` placeholder rather than to an expansion over the
+/// searchable fields. Measured, not assumed. That divergence from the FTS
/// projection predates this change and is called out in its own comment in
/// `doc_matches_query`; making it schema-aware means threading a schema
/// through ~79 call sites and is left as its own change.
@@ -26968,6 +26982,13 @@ fn declared_field<'a>(schema: &'a Schema, field: &str) -> Option<&'a FieldConfig
/// `server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java:1534-1546`)
/// which it raises whether or not `index: false` was declared — a wider
/// divergence than this change, and one this error message would misreport.
+///
+/// And one surface never reaches this function at all: `_validate/query`
+/// (`xerj-api/src/es_compat.rs::validate_query`) answers from the parse alone
+/// and never opens the index, so it still reports `{"valid": true}` for a body
+/// `_search` refuses. That is its behaviour on `main` too — this change did
+/// not alter it — but it now disagrees with `_search`, so it is written down
+/// here and in the CHANGELOG instead of being left to surprise someone.
fn unsearchable_query_field(q: &QueryNode, schema: &Schema) -> Option<String> {
let check = |field: &str| -> Option<String> {
let fc = declared_field(schema, field)?;