Skip to content

Support knn filter on nested metadata #2315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

mayya-sharipova
Copy link
Contributor

This is to update our documentation that we now can support knn filter on nested metadata.

Related to elastic/elasticsearch#113949

This is to update our documentation that we now can support
knn filter on nested metadata.

Related to elastic/elasticsearch#113949
@mayya-sharipova mayya-sharipova requested a review from a team as a code owner July 29, 2025 18:06
Copy link

github-actions bot commented Jul 29, 2025

🔍 Preview links for changed docs

@leemthompo
Copy link
Contributor

leemthompo commented Jul 30, 2025

Hi @mayya-sharipova, just a note that if you're adding sections or information that pertains to specific versions, i.e. 9.2 in this case, you'll need to use applies_to tags to signal that on the page. Because the 9.x docs all live on one page nowadays instead of having separate minor version branches for each docs page.

For example, here's a section-level applies to used just after a heading:

## My new heading for a new feature
```{applies_to}
stack: ga 9.2
```

This means we shouldn't delete information from a page, or change pre-existing information without the correct tags. We can use applies_to at page level, section level, and inline where necessary: https://elastic.github.io/docs-builder/syntax/applies/#when-and-where-to-use-applies_to

Feel free to reach out on #docs if need an assist :)

@mayya-sharipova
Copy link
Contributor Author

mayya-sharipova commented Jul 30, 2025

@leemthompo Thanks for the update. Would appreciate your help structuring the following:

I have this section that is not true anymore from 9.2. How to indicate that is only applicable before 9.2 release? Is there a way to say applies before 9.2?

What if you wanted to filter by some top-level document metadata? You can do this by adding `filter` to your `knn` clause.

::::{note}
`filter` will always be over the top-level document metadata. This means you cannot filter based on `nested` field metadata.

How it should be modified to this from 9.2 release.

What if you wanted to filter by some top-level or nested metadata? You can do this by adding `filter` to your `knn` clause.

::::{note}
To ensure correct results: each individual filter must be either over
the top-level metadata or `nested` metadata. However, a single knn search
supports multiple filters, where some filters can be over the top-level
metadata and some over nested.
::::

@leemthompo
Copy link
Contributor

leemthompo commented Jul 30, 2025

@mayya-sharipova Can achieve this by basically saying you have two ways to filter and noting that the nested metadata option is only available in 9.2+?

Something like this:

Want to filter by metadata? You can do this by adding `filter` to your `knn` clause.

To ensure correct results, each individual filter must be either over:

-  Top-level metadata 
- `nested` metadata {applies_to}`stack: ga 9.2`
  :::{note}
  A single `knn` search supports multiple filters, where some filters can be over the top-level metadata and some over nested.
  :::

That way it's clear that the second option is only available in 9.2+.

@mayya-sharipova
Copy link
Contributor Author

Thanks @leemthompo, I've added applies_to 9.2 in the last commit.

Copy link
Contributor

@leemthompo leemthompo left a comment

Choose a reason for hiding this comment

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

Thanks for working with the applies_to markers @mayya-sharipova! 🙏

LGTM, with a few minor suggestions. Not sure if you want a peer dev review on the technical details before merging.

@mayya-sharipova
Copy link
Contributor Author

@leemthompo Thanks for review, I've committed your changes.

Not sure if you want a peer dev review on the technical details before merging.

The main Elasticsearch PR that introduces similar changes to knn query documentation has been already approved, so I think it is not necessary for another approval on the technical details.

@mayya-sharipova mayya-sharipova merged commit d95218b into elastic:main Jul 30, 2025
8 checks passed
@mayya-sharipova mayya-sharipova deleted the knn-search-filter-on-nested-fields branch July 30, 2025 15:46
@leemthompo
Copy link
Contributor

@mayya-sharipova gotcha, but bad news is we need applies_to's also in the elasticsearch docs nowadays. If you create a docs issue the docs team can fix this instance, by recreating what we did here —but we really need devs to help enforce this too when reviewing PRs, once up to speed with the model. 🙏

I dropped a note in Slack recently to repeat the signal :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants