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.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(query): empty match/match_phrase/match_phrase_prefix query -> 400
Vincenzo Lombardo5e02cef33fd1
diff --git a/engine/crates/xerj-query/src/parser.rs b/engine/crates/xerj-query/src/parser.rsindex b4ef5cd72..7f1ee9d1d 100644--- a/engine/crates/xerj-query/src/parser.rs+++ b/engine/crates/xerj-query/src/parser.rs@@ -369,6 +369,15 @@ fn parse_match(params: &Value) -> Result<QueryNode> {let (field, value) = obj.iter().next().unwrap();let field = field.clone();+ // An empty query string is valid ES syntax that simply has no analyzed+ // terms to match — real ES treats it leniently (match_none), not as a+ // parse error. Kibana's own SavedObjectsClient `_find` builds exactly+ // this for a trailing-`*` search term (`"*".replace(/\*$/, '')` →+ // `""`), so without this every `_find?search=*` 400s.+ if matches!(value, Value::String(s) if s.is_empty()) {+ return Ok(QueryNode::MatchNone);+ }+// Shorthand forms: `match: {field: "value"}`, `match: {field: 42}`,// `match: {field: true}`. ES silently stringifies non-strings.if let Some(query) = scalar_to_string(value) {@@ -386,6 +395,10 @@ fn parse_match(params: &Value) -> Result<QueryNode> {.as_object().ok_or_else(|| qerr("`match` field value must be a scalar or object"))?;+ if matches!(vobj.get("query"), Some(Value::String(s)) if s.is_empty()) {+ return Ok(QueryNode::MatchNone);+ }+// Inside the object form, `query` can also be a number / bool.let query = vobj.get("query")@@ -439,6 +452,11 @@ fn parse_match_phrase(params: &Value) -> Result<QueryNode> {let (field, value) = obj.iter().next().unwrap();let field = field.clone();+ // Empty query string → match_none, not a parse error. See `parse_match`.+ if matches!(value, Value::String(s) if s.is_empty()) {+ return Ok(QueryNode::MatchNone);+ }+// Shorthand forms: `match_phrase: {field: "value"}`, `match_phrase:// {field: 42}`, `match_phrase: {field: true}` — ES silently stringifies// non-strings, same as `match` (see `scalar_to_string`).@@ -456,6 +474,10 @@ fn parse_match_phrase(params: &Value) -> Result<QueryNode> {.as_object().ok_or_else(|| qerr("`match_phrase` field value must be a string or object"))?;+ if matches!(vobj.get("query"), Some(Value::String(s)) if s.is_empty()) {+ return Ok(QueryNode::MatchNone);+ }+// Inside the object form, `query` can also be a number / bool — e.g.// OpenSearch Dashboards filtering on a boolean field sends// `match_phrase: {field: {query: true}}` verbatim (found empirically,@@ -1785,6 +1807,13 @@ fn parse_match_phrase_prefix(params: &Value) -> Result<QueryNode> {let (field, raw) = obj.iter().next().unwrap();let field = field.clone();+ // Empty query string → match_none, not a parse error. See `parse_match`.+ // This is exactly what Kibana's own SavedObjectsClient `_find` builds+ // for a trailing-`*` search term.+ if matches!(raw, Value::String(s) if s.is_empty()) {+ return Ok(QueryNode::MatchNone);+ }+// Shorthand forms: `match_phrase_prefix: {field: "value"}`, `{field:// 42}`, `{field: true}` — ES silently stringifies non-strings, same as// `match` (see `scalar_to_string`).@@ -1800,6 +1829,10 @@ fn parse_match_phrase_prefix(params: &Value) -> Result<QueryNode> {.as_object().ok_or_else(|| qerr("`match_phrase_prefix` field value must be a string or object"))?;+ if matches!(inner.get("query"), Some(Value::String(s)) if s.is_empty()) {+ return Ok(QueryNode::MatchNone);+ }+let query = inner.get("query").and_then(scalar_to_string)