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(api): match a mid-name wildcard in index patterns (#1933) (#1937)
xerj-org0fe70fe27636
diff --git a/engine/crates/xerj-api/src/es_compat.rs b/engine/crates/xerj-api/src/es_compat.rsindex c4d256b57..d8ddc50dc 100644--- a/engine/crates/xerj-api/src/es_compat.rs+++ b/engine/crates/xerj-api/src/es_compat.rs@@ -27836,17 +27836,69 @@ fn es_aggregator_class_name_ctx(}}+/// `*`-only glob over an index, alias or field name: `*` matches any run of+/// characters (including none), anywhere in the pattern, any number of times.+/// Every other character is literal, as in ES index patterns (`?` is not a+/// wildcard there).+///+/// This used to handle one leading or one trailing `*` and fall back to+/// string equality for anything else, so `logs-*-2026` (#1933) and+/// `*-app-*` matched nothing and `_search` answered 0 hits with no error.fn glob_match_simple(pattern: &str, name: &str) -> bool {- if pattern == "*" {- return true;+ if !pattern.contains('*') {+ return pattern == name;}- if let Some(prefix) = pattern.strip_suffix('*') {- return name.starts_with(prefix);+ let mut parts = pattern.split('*');+ // `split` always yields at least one item; the first is anchored at the+ // start of `name`, the last at its end, the middle ones float in order.+ let first = parts.next().unwrap_or("");+ let Some(mut rest) = name.strip_prefix(first) else {+ return false;+ };+ let middle: Vec<&str> = parts.collect();+ let Some((last, middle)) = middle.split_last() else {+ return true;+ };+ for part in middle {+ if part.is_empty() {+ continue;+ }+ match rest.find(part) {+ Some(at) => rest = &rest[at + part.len()..],+ None => return false,+ }}- if let Some(suffix) = pattern.strip_prefix('*') {- return name.ends_with(suffix);+ rest.ends_with(last)+}++#[cfg(test)]+mod glob_match_simple_tests {+ use super::glob_match_simple;++ #[test]+ fn a_star_anywhere_in_an_index_pattern_matches() {+ // #1933: a mid-name `*` used to fall through to string equality.+ assert!(glob_match_simple("logs-*-2026", "logs-app-2026"));+ assert!(glob_match_simple("logs-*-2026", "logs--2026"));+ assert!(!glob_match_simple("logs-*-2026", "logs-app-2025"));+ assert!(glob_match_simple("*-app-*", "logs-app-2026"));+ assert!(glob_match_simple("l*s-*-20*6", "logs-app-2026"));+ assert!(+ !glob_match_simple("ab*ba", "aba"),+ "anchors may not overlap"+ );+ assert!(glob_match_simple("a**b", "ab"));+ // Unchanged shapes.+ assert!(glob_match_simple("*", "anything"));+ assert!(glob_match_simple("logs-*", "logs-app-2026"));+ assert!(glob_match_simple("*-2026", "logs-app-2026"));+ assert!(glob_match_simple("logs-app-2026", "logs-app-2026"));+ assert!(!glob_match_simple("logs-app", "logs-app-2026"));+ assert!(+ !glob_match_simple("logs-?pp-2026", "logs-app-2026"),+ "`?` is literal"+ );}- pattern == name}// ─────────────────────────────────────────────────────────────────────────────diff --git a/engine/crates/xerj-api/tests/index_pattern_mid_wildcard.rs b/engine/crates/xerj-api/tests/index_pattern_mid_wildcard.rsnew file mode 100644index 000000000..41bf0320f--- /dev/null+++ b/engine/crates/xerj-api/tests/index_pattern_mid_wildcard.rs@@ -0,0 +1,120 @@+//! Issue #1933: an index pattern with `*` in the middle (`logs-*-2026`)+//! matched no index, so `_search` answered 200 with 0 hits and no error.+//! Leading and trailing wildcards worked. The matcher behind it+//! (`glob_match_simple`) is shared by `_search`, `_count`, `GET /{index}` and+//! the other index-selector endpoints, so this pins the read paths an agent+//! hits first.+//!+//! Elasticsearch is referenced for wire semantics only; no ES code is+//! reproduced here.++use axum::body::Body;+use axum::http::{Request, StatusCode};+use serde_json::{json, Value};+use tower::ServiceExt;++async fn app() -> (axum::Router, tempfile::TempDir) {+ let dir = tempfile::tempdir().expect("tempdir");+ let mut config = xerj_common::config::Config::default();+ config.server.data_dir = dir.path().to_string_lossy().into_owned();+ config.storage.wal_sync = xerj_common::config::WalSync::Async;+ let metrics = xerj_common::metrics::Metrics::new().expect("metrics");+ let engine = xerj_engine::Engine::new(config.clone()).expect("engine");+ let state = xerj_api::state::AppState::new(config, engine, metrics);+ (xerj_api::router::build_es_compat_router(state), dir)+}++async fn send(app: &axum::Router, method: &str, path: &str, body: Value) -> (StatusCode, Value) {+ let mut req = Request::builder().method(method).uri(path);+ let body = if body.is_null() {+ String::new()+ } else {+ req = req.header("content-type", "application/json");+ body.to_string()+ };+ let response = app+ .clone()+ .oneshot(req.body(Body::from(body)).unwrap())+ .await+ .unwrap();+ let status = response.status();+ let bytes = axum::body::to_bytes(response.into_body(), usize::MAX)+ .await+ .unwrap();+ (+ status,+ serde_json::from_slice(&bytes).unwrap_or(Value::Null),+ )+}++async fn seeded() -> (axum::Router, tempfile::TempDir) {+ let (app, dir) = app().await;+ for index in ["logs-app-2026", "logs-web-2026", "logs-app-2025"] {+ let (st, resp) = send(+ &app,+ "PUT",+ &format!("/{index}"),+ json!({"mappings": {"properties": {"msg": {"type": "text"}}}}),+ )+ .await;+ assert_eq!(st, StatusCode::OK, "create {index}: {resp}");+ let (st, resp) = send(+ &app,+ "PUT",+ &format!("/{index}/_doc/1?refresh=true"),+ json!({"msg": format!("disk full on {index}")}),+ )+ .await;+ assert_eq!(st, StatusCode::CREATED, "index into {index}: {resp}");+ }+ (app, dir)+}++fn hit_indices(resp: &Value) -> Vec<String> {+ let mut out: Vec<String> = resp["hits"]["hits"]+ .as_array()+ .unwrap_or(&Vec::new())+ .iter()+ .filter_map(|h| h["_index"].as_str().map(str::to_string))+ .collect();+ out.sort();+ out+}++#[tokio::test]+async fn search_resolves_a_mid_name_wildcard() {+ let (app, _dir) = seeded().await;+ let query = json!({"query": {"match": {"msg": "disk"}}});++ let (st, resp) = send(&app, "POST", "/logs-*-2026/_search", query.clone()).await;+ assert_eq!(st, StatusCode::OK, "{resp}");+ assert_eq!(resp["hits"]["total"]["value"], 2, "{resp}");+ assert_eq!(+ hit_indices(&resp),+ ["logs-app-2026", "logs-web-2026"],+ "{resp}"+ );++ // Two stars, one of them in the middle.+ let (st, resp) = send(&app, "POST", "/*-app-*/_search", query.clone()).await;+ assert_eq!(st, StatusCode::OK, "{resp}");+ assert_eq!(+ hit_indices(&resp),+ ["logs-app-2025", "logs-app-2026"],+ "{resp}"+ );++ let (st, resp) = send(&app, "POST", "/logs-*-2026/_count", query).await;+ assert_eq!(st, StatusCode::OK, "{resp}");+ assert_eq!(resp["count"], 2, "{resp}");+}++#[tokio::test]+async fn get_index_resolves_a_mid_name_wildcard() {+ let (app, _dir) = seeded().await;+ let (st, resp) = send(&app, "GET", "/logs-*-2026", Value::Null).await;+ assert_eq!(st, StatusCode::OK, "{resp}");+ let mut names: Vec<&String> = resp.as_object().expect("object").keys().collect();+ names.sort();+ assert_eq!(names, ["logs-app-2026", "logs-web-2026"], "{resp}");+}