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(engine): Painless doc['field'].value has no date accessor methods
Vincenzo Lombardob2b03e61f7ac
diff --git a/engine/crates/xerj-engine/src/painless.rs b/engine/crates/xerj-engine/src/painless.rsindex 7da3522e1..ada3faef5 100644--- a/engine/crates/xerj-engine/src/painless.rs+++ b/engine/crates/xerj-engine/src/painless.rs@@ -1084,6 +1084,19 @@ fn eval_expr("toString" => return Ok(PainlessValue::String(s.clone())),"toLowerCase" => return Ok(PainlessValue::String(s.to_lowercase())),"toUpperCase" => return Ok(PainlessValue::String(s.to_uppercase())),+ // `doc['a_date_field'].value` returns the raw ISO string+ // (real ES returns a JodaCompatibleZonedDateTime, which+ // these getters read off directly) — so date accessor+ // methods here parse the string on demand instead. Only+ // dispatches for these specific getter names, so a+ // genuinely non-date string field still falls through+ // to the "unsupported member access" error below.+ "getHour" | "getMinute" | "getSecond" | "getDayOfMonth" | "getMonthValue"+ | "getYear" | "getDayOfWeek" => {+ if let Some(ms) = date_value_millis(s) {+ return date_component(ms, member);+ }+ }_ => {}}}@@ -1204,6 +1217,35 @@ fn resolve_doc_member(}}+/// Parse an ISO-8601-ish date string into epoch milliseconds (UTC),+/// reusing the same parser aggregations use for date fields so a date's+/// script-accessor components (getHour, getDayOfWeek, ...) agree with+/// how the same value is bucketed elsewhere.+fn date_value_millis(s: &str) -> Option<i64> {+ crate::aggs::parse_date_ms(&Value::String(s.to_string()))+}++/// Extract one Java `ZonedDateTime`-style component (UTC) from an epoch-ms+/// value, for the `doc['a_date_field'].value.getXxx()` accessor family.+fn date_component(ms: i64, member: &str) -> Result<PainlessValue, String> {+ use chrono::{Datelike, Timelike};+ let dt = chrono::DateTime::<chrono::Utc>::from_timestamp_millis(ms)+ .ok_or_else(|| format!("invalid date value for .{}", member))?;+ let n = match member {+ "getHour" => dt.hour(),+ "getMinute" => dt.minute(),+ "getSecond" => dt.second(),+ "getDayOfMonth" => dt.day(),+ "getMonthValue" => dt.month(),+ "getYear" => dt.year() as u32,+ // Java DayOfWeek: MONDAY=1 .. SUNDAY=7 (chrono's weekday() already+ // uses the same Monday-first ordinal via num_days_from_monday).+ "getDayOfWeek" => dt.weekday().num_days_from_monday() + 1,+ _ => return Err(format!("unsupported date member .{}", member)),+ };+ Ok(PainlessValue::Number(n as f64))+}+fn get_doc_value(doc: &Value, field: &str) -> Value {let parts: Vec<&str> = field.split('.').collect();let mut cur = doc.clone();