Skip to content

MB-27666: Fix nested mode handling for field-implicit queries#2272

Merged
CascadingRadium merged 6 commits intomasterfrom
bugFix
Jan 19, 2026
Merged

MB-27666: Fix nested mode handling for field-implicit queries#2272
CascadingRadium merged 6 commits intomasterfrom
bugFix

Conversation

@CascadingRadium
Copy link
Copy Markdown
Member

@CascadingRadium CascadingRadium commented Jan 16, 2026

  • Fix nested-mode search for field-implicit queries (match_all, docID): These queries previously filtered nested documents at the searcher level, but since ExtractFields returned no fields, the nested collector was never activated. In compound queries (e.g., Boolean filters), this caused a level mismatch—searcher filtering vs nested-level execution—resulting in zero matches.
  • Unify filtering at collector level: Introduced HasID() and HasAll() flags in FieldSet to track field-implicit queries. Removed searcher-level filtering from MatchAllSearcher.
  • Nested collector now correctly activates, ensuring consistent behavior regardless of query composition.
  • Fix an edge case where usage of match_all query as a sub-clause in a NestedConjunctionSearcher could cause a panic.
  • Fix a case where root document fields would get excluded from the _all field even when included.
  • Fix outdated information in hierarchy.md
  • Add unit tests for Hierarchical Nested Vector Search.

@CascadingRadium CascadingRadium changed the title Fix logic for nested field agnostic queries Fix nested mode handling for field-agnostic queries Jan 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug in nested-mode search where field-agnostic queries (match_all, docID) were incorrectly filtered at the searcher level instead of the collector level. The issue caused zero matches when these queries were used in compound queries (e.g., Boolean filters) due to a level mismatch between searcher filtering and nested-level execution.

Changes:

  • Introduced a Global() flag in the FieldSet interface to identify field-agnostic queries
  • Removed searcher-level nested document filtering from MatchAllSearcher
  • Updated nested collector activation logic to trigger for global queries, ensuring consistent filtering at the collector level

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
search/util.go Converted FieldSet from a map type to an interface with a private implementation, adding Global() flag to track field-agnostic queries
search/query/query.go Updated ExtractFields to set the Global() flag for MatchAllQuery and DocIDQuery
search/searcher/search_match_all.go Removed nested document filtering logic (isNested method) to unify filtering at collector level
index_impl.go Enhanced nested collector activation logic to include global queries; refactored field iteration to use VisitFields
registry/nested.go Adapted to new FieldSet interface using VisitFields method
index_alias_impl.go Updated field iteration to use new FieldSet.VisitFields API
mapping/index.go Updated method call from Slice() to Fields()
search_nested_test.go Added comprehensive test cases for match_all, docID, and Boolean filter queries in nested mode
search/query/query_test.go Extended test coverage for field extraction with expGlobal assertions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread search/util.go
Comment thread index_impl.go Outdated
Comment thread index_impl.go Outdated
Comment thread registry/nested.go Outdated
Comment thread registry/nested.go Outdated
@coveralls
Copy link
Copy Markdown

coveralls commented Jan 16, 2026

Coverage Status

coverage: 52.657% (+0.04%) from 52.621%
when pulling 4d4984d on bugFix
into ca7d4ab on master.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread index_alias_impl.go Outdated
@abhinavdangeti abhinavdangeti changed the title Fix nested mode handling for field-agnostic queries MB-27666: Fix nested mode handling for field-agnostic queries Jan 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Comment thread search/util.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

registry/nested.go:1

  • Potential panic when accessing ancestors[len(ancestors)-pos-1] if ancestors is empty or if pos >= len(ancestors). With the changes allowing global queries in nested contexts, this function may be called with empty ancestor chains from top-level documents matched by match_all queries. Add bounds checking to prevent panics.
//  Copyright (c) 2026 Couchbase, Inc.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread search/query/conjunction.go
Comment thread search/query/query.go Outdated
Comment thread search/util.go Outdated
Comment thread search/util.go Outdated
@CascadingRadium CascadingRadium changed the title MB-27666: Fix nested mode handling for field-agnostic queries MB-27666: Fix nested mode handling for field-implicit queries Jan 19, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@CascadingRadium CascadingRadium merged commit 56a2d57 into master Jan 19, 2026
10 checks passed
@CascadingRadium CascadingRadium deleted the bugFix branch January 19, 2026 20:39
CascadingRadium added a commit that referenced this pull request Jan 20, 2026
- Fix nested-mode search for field-implicit queries (`match_all`,
`docID`): These queries previously filtered nested documents at the
searcher level, but since `ExtractFields` returned no fields, the nested
collector was never activated. In compound queries (e.g., Boolean
filters), this caused a level mismatch—searcher filtering vs
nested-level execution—resulting in zero matches.
- Unify filtering at collector level: Introduced `HasID()` and
`HasAll()` flags in `FieldSet` to track field-implicit queries. Removed
searcher-level filtering from `MatchAllSearcher`.
- Nested collector now correctly activates, ensuring consistent behavior
regardless of query composition.
- Fix an edge case where usage of `match_all query` as a sub-clause in a
`NestedConjunctionSearcher` could cause a panic.
- Fix a case where root document fields would get excluded from the
`_all` field even when included.
- Fix outdated information in `hierarchy.md`
- Add unit tests for Hierarchical Nested Vector Search.
CascadingRadium added a commit that referenced this pull request Jan 21, 2026
- Backport the following commits into `v8.0.x-couchbase` via cherry-pick
    - #2270
    - #2224
    - #2272

---------

Co-authored-by: Abhinav Dangeti <abhinav@couchbase.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants