Skip to content

Extend LAST and LATEST to support the same field types as FIRST and EARLIEST - #152154

Merged
lefteris-z merged 22 commits into
elastic:mainfrom
lefteris-z:fix/149478
Jul 2, 2026
Merged

lefteris-z merged 22 commits into
elastic:mainfrom
lefteris-z:fix/149478

Conversation

@lefteris-z

@lefteris-z lefteris-z commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Extends the ESQL LAST and LATEST aggregate functions to accept the same field types as FIRST and EARLIEST.

Since LATEST is a surrogate for LAST(field, @timestamp), both should be brought to parity.

The simple-reuse types introduce no new aggregators they wire to the BytesRef or Long suppliers that already existed for LAST. For the most complex types:

Type Block type NULL sort LONG/DATETIME sort INT sort
version BytesRefBlock Reuses AnyBytesRef Reuses AllLastBytesRefByLong Reuses AllLastBytesRefByInt
geo_point BytesRefBlock Reuses AnyBytesRef Reuses AllLastBytesRefByLong Reuses AllLastBytesRefByInt
geo_shape BytesRefBlock Reuses AnyBytesRef Reuses AllLastBytesRefByLong Reuses AllLastBytesRefByInt
cartesian_point BytesRefBlock Reuses AnyBytesRef Reuses AllLastBytesRefByLong Reuses AllLastBytesRefByInt
cartesian_shape BytesRefBlock Reuses AnyBytesRef Reuses AllLastBytesRefByLong Reuses AllLastBytesRefByInt
unsigned_long LongBlock Reuses AnyLong Reuses AllLastLongByLong Reuses AllLastLongByInt
geohash LongBlock Reuses AnyLong Reuses AllLastLongByLong Reuses AllLastLongByInt
geotile LongBlock Reuses AnyLong Reuses AllLastLongByLong Reuses AllLastLongByInt
geohex LongBlock Reuses AnyLong Reuses AllLastLongByLong Reuses AllLastLongByInt
dense_vector FloatBlock (multi-valued) Reuses AnyFloat Reuses AllLastFloatByLong Reuses AllLastFloatByInt
exponential_histogram ExponentialHistogramBlock Reuses AnyExponentialHistogram AllLastExponentialHistogramByLong (renamed from LastExponentialHistogramByTimestamp) New AllLastExponentialHistogramByInt
tdigest TDigestBlock Reuses AnyTDigest AllLastTDigestByLong (renamed from LastTDigestByTimestamp) New AllLastTDigestByInt
flattened BytesRefBlock Reuses AnyBytesRef Reuses AllLastBytesRefByLong Reuses AllLastBytesRefByInt

Extras

  • flattened: newly supported on LAST/LATEST. FIRST/EARLIEST already supported flattened but were missing the @FunctionInfo declaration, this PR adds that to keep things consistent.
  • Integration tests added to stats_first_last.csv-spec and stats_earliest_latest.csv-spec.

Follows on from #149307 and #149716 which added these types to FIRST/EARLIEST

Closes #149478

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

🔍 Preview links for changed docs

⏳ Building and deploying preview... View progress

This comment will be updated with preview links when the build is complete.

@github-actions

Copy link
Copy Markdown
Contributor

ℹ️ Important: Docs version tagging

👋 Thanks for updating the docs! Just a friendly reminder that our docs are now cumulative. This means all 9.x versions are documented on the same page and published off of the main branch, instead of creating separate pages for each minor version.

We use applies_to tags to mark version-specific features and changes.

Expand for a quick overview

When to use applies_to tags:

✅ At the page level to indicate which products/deployments the content applies to (mandatory)
✅ When features change state (e.g. preview, ga) in a specific version
✅ When availability differs across deployments and environments

What NOT to do:

❌ Don't remove or replace information that applies to an older version
❌ Don't add new information that applies to a specific version without an applies_to tag
❌ Don't forget that applies_to tags can be used at the page, section, and inline level

🤔 Need help?

@lefteris-z lefteris-z self-assigned this Jun 25, 2026
@lefteris-z lefteris-z added >enhancement Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch :Search Relevance/ES|QL Search functionality in ES|QL labels Jun 25, 2026
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Hi @lefteris-z, I've created a changelog YAML for you.

@lefteris-z
lefteris-z requested a review from dnhatn June 25, 2026 14:35
@lefteris-z lefteris-z changed the title Fix/149478 Extend LAST and LATEST to support the same field types as FIRST and EARLIEST Jun 25, 2026
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Hi @lefteris-z, I've updated the changelog YAML for you.

@lefteris-z
lefteris-z marked this pull request as ready for review June 26, 2026 10:06
@lefteris-z
lefteris-z requested a review from a team as a code owner June 26, 2026 10:06
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

@lefteris-z
lefteris-z merged commit 068b128 into elastic:main Jul 2, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement :Search Relevance/ES|QL Search functionality in ES|QL Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend LAST and LATEST to support the same field types as FIRST and EARLIEST

4 participants