fix(engine): Painless doc['field'].value has no date accessor methods - #51
Merged
Merged
Conversation
`doc['a_date_field'].value` returned the raw ISO-8601 string as a plain Painless String, so any date accessor method chained onto it (`.getHour()`, `.getDayOfWeek()`, etc. -- the standard Painless/Java ZonedDateTime API real Elasticsearch exposes there) fell through to the generic "unsupported member access" error and the whole script silently failed. This blocks any Kibana visualization whose bucket or metric dimension is a date-component script -- most visibly the sample "Heat Map" visualization, which buckets its Y-axis by `doc['timestamp'].value.getHour()`. Fix: when a getter from the common date-accessor set (getHour, getMinute, getSecond, getDayOfMonth, getMonthValue, getYear, getDayOfWeek) is called on a String value, parse it as a date via the same parser aggregations already use for date fields (`aggs::parse_date_ms`) and extract the requested UTC component. A string that isn't a parseable date (or a getter outside this set) still falls through unchanged to the existing unsupported-member error -- this only adds a narrow, additive dispatch, it doesn't change how any other String method resolves. Combined with the terms-aggregation script fix (separate PR), this fully unblocks the sample Heat Map visualization's date-script Y-axis end to end. Verified: `doc['timestamp'].value.getHour()` via script_fields now returns the correct UTC hour (5, 14, 14 for three test timestamps) instead of silently producing no `fields` output. Full ES-compat YAML conformance suite: 1360 passed, 0 failed, 3 skipped -- no regressions. 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.
Summary
doc['a_date_field'].valuereturns the raw ISO-8601 string as a plain PainlessString, so any date accessor method chained onto it (.getHour(),.getDayOfWeek(), etc. — the standard Painless/JavaZonedDateTimeAPI real Elasticsearch exposes there) fell through to the generic "unsupported member access" error, and the whole script silently failed. This blocks any Kibana visualization whose bucket or metric dimension is a date-component script — most visibly the sample "Heat Map" visualization, which buckets its Y-axis bydoc['timestamp'].value.getHour().Fix
When one of the common date-accessor getters (
getHour,getMinute,getSecond,getDayOfMonth,getMonthValue,getYear,getDayOfWeek) is called on aStringvalue, parse it as a date via the same parser aggregations already use for date fields (aggs::parse_date_ms) and extract the requested UTC component. A string that isn't a parseable date (or a getter outside this set) still falls through unchanged to the existing unsupported-member error — this only adds a narrow, additive dispatch, it doesn't change how any other String method resolves.Paired with #50 (terms aggregation
scriptsupport), this fully unblocks the sample Heat Map visualization's date-script Y-axis end to end.Test plan
cargo build --release -p xerj-api -p xerj-engine -p xerj-servercargo fmt --check/cargo clippy --no-deps -- -D warnings— cleandoc['timestamp'].value.getHour()viascript_fieldsnow returns the correct UTC hour (5, 14, 14 for three test timestamps) instead of silently producing nofieldsoutput🤖 Generated with Claude Code