Skip to content

Add TOP_SNIPPETS function to return the best snippets for a field#138940

Merged
kderusso merged 19 commits intoelastic:mainfrom
kderusso:kderusso/esql-top-snippets
Dec 9, 2025
Merged

Add TOP_SNIPPETS function to return the best snippets for a field#138940
kderusso merged 19 commits intoelastic:mainfrom
kderusso:kderusso/esql-top-snippets

Conversation

@kderusso
Copy link
Member

@kderusso kderusso commented Dec 2, 2025

Adds a TOP_SNIPPETS function to return the best snippets for a field.

Example usage:

EVAL snippets = TOP_SNIPPETS(description, "Tolkien", { "num_snippets": 3, "num_words": 25 })
@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

ℹ️ 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?

@kderusso kderusso added >enhancement :Search Relevance/ES|QL Search functionality in ES|QL labels Dec 3, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @kderusso, I've created a changelog YAML for you.

@kderusso kderusso marked this pull request as ready for review December 3, 2025 13:29
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Dec 3, 2025
Copy link
Contributor

@ioanatia ioanatia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks on the right track

public TopSnippets(
Source source,
@Param(name = "field", type = { "keyword", "text" }, description = "The input to chunk.") Expression field,
@Param(name = "query", type = { "keyword" }, description = "The query string to extract the best snippets for.") Expression query,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to be clear what kind of query this actually is. Query string seems like qstr but it isn't. Is this a match query? Is it qstr? Is it just a term query? Does it accept wildcards?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the docs, LMKWYT

@kderusso kderusso requested a review from ioanatia December 4, 2025 20:29
Copy link
Member

@benwtrent benwtrent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks ok to me. ESQL experts should review of course.

Copy link
Member

@carlosdelest carlosdelest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 🎉

We need to support NULL as a field, so we don't error out for multi index queries. Once that's done this is ready to go from my side.

Some other minor comments.

@kderusso kderusso requested a review from carlosdelest December 5, 2025 21:26
Copy link
Member

@carlosdelest carlosdelest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@kderusso kderusso merged commit d6f64a6 into elastic:main Dec 9, 2025
34 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.3.0

5 participants