Skip to content

fix(query): empty match/match_phrase/match_phrase_prefix query -> 400 - #45

Merged
xerj-org merged 2 commits into
xerj-org:mainfrom
Vinz2168:fix/empty-match-query-none
Jul 27, 2026
Merged

fix(query): empty match/match_phrase/match_phrase_prefix query -> 400#45
xerj-org merged 2 commits into
xerj-org:mainfrom
Vinz2168:fix/empty-match-query-none

Conversation

@Vinz2168

Copy link
Copy Markdown
Collaborator

⚠️ Stacked on #32

This branch is cut from fix/match-phrase-scalar-coercion (open PR #32, not yet merged) because the match_phrase/match_phrase_prefix parse functions this fix touches are the same ones #32 modifies. The diff will show #32's commits until that PR merges — the actual new change here is the final commit only ("fix(query): empty match/match_phrase/match_phrase_prefix query -> 400").

Summary

parse_match/parse_match_phrase/parse_match_phrase_prefix treated an empty query string as a hard parse error, in both the shorthand form (match: {field: ""}) and the object form (match: {field: {query: ""}}).

Root cause

Real ES is lenient here: an empty analyzed query string simply has no terms to match, so it resolves to zero results rather than a 400. This is exactly what Kibana's own SavedObjectsClient._find endpoint builds for a trailing-* search term ("*".replace(/\*$/, '')"") via a match_phrase_prefix sub-clause — so every _find?search=* call (index-pattern search, saved-objects management, and anything else built on the default "list everything" search) 400'd.

Fix

Return QueryNode::MatchNone for an empty query string in all three parse functions, before the existing scalar/object-form branching — covers both the shorthand and object forms.

Test plan

  • cargo build --release -p xerj-api -p xerj-server
  • cargo fmt --check / cargo clippy --no-deps -- -D warnings — clean
  • cargo test --release -p xerj-query --lib — passed
  • _find?search=*&search_fields=title&type=index-pattern through a real Kibana OSS 7.10.2 instance now returns 200 (previously 400)
  • Direct match_phrase_prefix with query: "" now returns 200 with zero hits instead of a parse error

🤖 Generated with Claude Code

Vincenzo Lombardo and others added 2 commits July 26, 2026 10:19
…er) query values

Root-caused OpenSearch Dashboards' dashboard filter panels throwing a
fatal, unrecoverable error on every request whenever a filter pill
targets a boolean field -- e.g. a stock "Flights" sample-data
dashboard filtering on `FlightDelay: true`.

`match` already coerces non-string JSON scalars via the existing
`scalar_to_string()` helper (`match: {field: true}` == `match:
{field: "true"}`, matching real ES's documented leniency). But
`match_phrase` and `match_phrase_prefix` never got the same
treatment:

- The object form (`match_phrase: {field: {query: <value>}}`) called
  the strict `string_field()` helper, which requires `.as_str()` to
  succeed -- so `{"query": true}` (a JSON boolean, not a string)
  failed with `query must be a non-empty string`, a hard parse
  error surfaced to the client as `search_phase_execution_exception`.
- The shorthand form (`match_phrase: {field: value}`) only checked
  `value.as_str()`, so even a bare `match_phrase: {field: true}`
  hit the same wall.

OpenSearch Dashboards' own filter-bar-to-DSL translation sends
exactly this shape for a boolean-field filter --
`match_phrase: {FlightDelay: {query: true}}` -- captured directly
from a real OSD 2.11.1 container's traffic via
`x-opensearch-product-origin: opensearch-dashboards`. Every
aggregation-driven dashboard panel with that filter applied errored
out simultaneously (the filter is shared across all panels), which
is what actually surfaced as "errors on the aggregations" -- the
aggregations themselves were never the problem, the filter clause
feeding them was.

Fixed both `parse_match_phrase` and `parse_match_phrase_prefix` to
use the same `scalar_to_string()` lenient coercion `parse_match`
already uses, for both the shorthand and object forms.

Full ES-compat YAML conformance suite: 1360 passed, 0 failed, 3
skipped -- no regressions. `xerj-query` unit tests: 124 passed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016XJaZygeuRfZfUg2B8tPKU
`parse_match`/`parse_match_phrase`/`parse_match_phrase_prefix` treated
an empty query string as a hard parse error ("`match.query` must be a
non-empty scalar"), both in the shorthand form (`match: {field: ""}`)
and the object form (`match: {field: {query: ""}}`).

Real ES is lenient here: an empty analyzed query string simply has no
terms to match, so it resolves to zero results rather than a 400. This
is exactly what Kibana's own SavedObjectsClient `_find` endpoint
builds for a trailing-`*` search term
(`"*".replace(/\*$/, '')` -> `""`) via a `match_phrase_prefix`
sub-clause -- so every `_find?search=*` call (index-pattern search,
saved-objects management, and anything else built on the default
"list everything" search) 400'd.

Fixed by returning `QueryNode::MatchNone` for an empty query string
in all three parse functions, before the existing scalar/object-form
branching -- covers both the shorthand and object forms.

Verified: `_find?search=*&search_fields=title&type=index-pattern`
through a real Kibana instance now returns 200 (previously 400); a
direct `match_phrase_prefix` with `query: ""` now returns 200 with
zero hits.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016XJaZygeuRfZfUg2B8tPKU
@xerj-org
xerj-org merged commit 869c7f9 into xerj-org:main Jul 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants