fix(query): empty match/match_phrase/match_phrase_prefix query -> 400 - #45
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This branch is cut from
fix/match-phrase-scalar-coercion(open PR #32, not yet merged) because thematch_phrase/match_phrase_prefixparse 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_prefixtreated 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._findendpoint builds for a trailing-*search term ("*".replace(/\*$/, '')→"") via amatch_phrase_prefixsub-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::MatchNonefor 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-servercargo fmt --check/cargo clippy --no-deps -- -D warnings— cleancargo test --release -p xerj-query --lib— passed_find?search=*&search_fields=title&type=index-patternthrough a real Kibana OSS 7.10.2 instance now returns 200 (previously 400)match_phrase_prefixwithquery: ""now returns 200 with zero hits instead of a parse error🤖 Generated with Claude Code