fix(persistence): ES _lastUpdated honours ne/sa/eb/ap and OR-lists - #893
Merged
Conversation
The Elasticsearch _lastUpdated clause folded every value into one range map keyed only by gte/gt/lt/lte: ne, sa, eb and ap all degraded to eq, and a second comma-separated value overwrote the first. Expose the indexed date handler's precision logic as date::field_range and build _lastUpdated on it against the top-level last_updated field: eq at day precision is [day, day+1), ne its complement via must_not, sa/eb mirror gt/lt on the whole period, and OR lists become bool.should with minimum_should_match 1. A full-precision instant now compares as a scalar instead of an empty half-open range, which also fixes eq on indexed date parameters at full precision. Closes #892 Claude-Session: https://claude.ai/code/session_01334x1QZSmUsznAtEVcnVy7
9 tasks
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Closes #892
Follow-up from #876. Elasticsearch was the one backend whose
_lastUpdatedclause did not go through a precision-aware date builder.What was wrong
build_last_updated_clausewrote everySearchValueinto a singlerangemap keyed only bygte/gt/lt/lte:ne,sa,eb,apfell into the default arm and behaved aseq._lastUpdated=ne2026-09-01returned exactly the resources updated that day._lastUpdated=2026-09-01,2026-09-03silently became a single-value match.Fix
The indexed date handler's precision logic is now exposed as
date::field_range(field, value, prefix) -> DateRange, returning either a plainrange(Within) or one the caller must negate (Outside, forne). Both call sites build on it:nestedquery;nebecomesmust_notinside the nested bool, as before._lastUpdatedapplies it to the top-levellast_updatedfield, one clause per value, OR-combined withbool.should/minimum_should_match: 1.Semantics now match SQLite, MongoDB, and Postgres (#876):
eqat day precision is[day, day+1),neits complement,gt/sastart after the whole period,lt/ebend before it,lereaches the end of the period.One incidental fix: a full-precision instant (
2024-01-15T10:00:00Z) used to producegte X, lt X, an empty range, foreqon indexed date parameters as well. It now compares as a scalar (gte X, lte X), mirroring the degenerate-range fallback in the Postgres builder.Tests
date.rsunits:neis the negated precision range;sa/ebmirrorgt/lton the whole period; full-precision instants are scalar, not empty.query_builder.rsunits pin the emitted JSON for_lastUpdatedeq,ne,sa/eb, and a two-value OR list.es_integration_search_last_updated_ne_excludes_todaycreates a resource, assertseqon today matches it andneon today excludes it.Verified
cargo test -p helios-persistence --lib --features elasticsearch: 888 passed.elasticsearch_tests.rs: 32 passed.es_integration_search_last_updatedfails identically. CI's runner covers that leg.https://claude.ai/code/session_01334x1QZSmUsznAtEVcnVy7