Skip to content

SOLR-18197: Add root document query shortcut support to NestPathField#4512

Open
abumarjikar wants to merge 15 commits into
apache:mainfrom
abumarjikar:SOLR_18197_nest_path_easy_of_use
Open

SOLR-18197: Add root document query shortcut support to NestPathField#4512
abumarjikar wants to merge 15 commits into
apache:mainfrom
abumarjikar:SOLR_18197_nest_path_easy_of_use

Conversation

@abumarjikar

@abumarjikar abumarjikar commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/SOLR-18197

Description

This pull request introduces a quick and intuitive shortcut to query root documents within hierarchical/nested data structures using the NestPathField. Currently, finding root-level documents (which do not have a nested path defined) requires a more verbose or explicit query syntax. This change provides a cleaner "ease of use" developer experience when dealing with nested child documents.

Solution

When a query is made against this field with an empty value, a null value, or a root slash ("/"), it automatically constructs and returns a BooleanQuery that targets only top-level root documents. It accomplishes this by matching all documents and explicitly excluding any documents where the nested path field exists:

MUST: MatchAllDocsQuery

MUST_NOT: ExistenceQuery (for the NestPathField)

For all other standard path inputs, it safely falls back to the default super.getFieldQuery(...) behavior.

Tests

Please describe the tests you've developed or run to confirm this patch implements the feature or solves the problem.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide
  • I have added a changelog entry for my change

@dsmiley dsmiley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks. Looking to see this used widespread in code & docs. The goal is to ensure no user sees that ugly/confusing syntax that was previously necessary.

Comment thread changelog/unreleased/SOLR_18197_nest_path_easy_of_use.yml Outdated
Comment thread solr/core/src/java/org/apache/solr/schema/NestPathField.java Outdated
@abumarjikar abumarjikar requested a review from dsmiley June 10, 2026 06:27
@github-actions github-actions Bot added the tests label Jun 11, 2026
@abumarjikar abumarjikar marked this pull request as ready for review June 11, 2026 07:41
Comment thread solr/core/src/test/org/apache/solr/schema/TestNestPathField.java Outdated

@dsmiley dsmiley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

still definitely looking for the application of this in the codebase + doc updates

Comment thread solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java
@github-actions github-actions Bot added documentation Improvements or additions to documentation cat:index labels Jun 16, 2026
@abumarjikar abumarjikar requested a review from dsmiley June 16, 2026 05:29
Comment on lines -700 to +701
"parent_filt", "(*:* -{!prefix f='_nest_path_' v='" + parent_path + "/'})",
"parent_filt", "({!field f='_nest_path_' v='" + parent_path + "/'})",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That change has a different underlying query & semantic effect. Formerly it found all docs separate from that parent path, thus matched not only the root doc but also /aa and /ff if that exists, say. You changed it to only match documents at /aa exactly.

return params(
"q", "{!parent which=$parent_filt v=$child_q}",
"parent_filt", "(*:* -{!prefix f='_nest_path_' v='" + path + "'})",
"parent_filt", "({!field f='_nest_path_' v='" + path + "'})",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

again, these are not equivalent

@abumarjikar abumarjikar requested a review from dsmiley June 18, 2026 04:58

@dsmiley dsmiley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

more to do... not ready for my re-review

Comment thread solr/solr-ref-guide/modules/query-guide/pages/dense-vector-search.adoc Outdated
@abumarjikar abumarjikar requested a review from dsmiley June 19, 2026 05:36
@dsmiley

dsmiley commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Audit usages of org.apache.solr.schema.IndexSchema#NEST_PATH_FIELD_NAME and you will find code that can be updated.

@abumarjikar

Copy link
Copy Markdown
Contributor Author

@dsmiley I audited the usage of IndexSchema#NEST_PATH_FIELD_NAME as suggested, and here is where I updated the logic (and where I intentionally left it out):

  1. Updated buildAllParentsFilterFromPath: > I replaced the manual, verbose BooleanQuery builder block for the root path (/ or empty) by directly delegating to my new nestPathField.getType().getFieldQuery(this, nestPathField, "/") logic. This completely removes the redundant manual construction of the "match all minus existence" pattern and unifies it under the new shortcut.

  2. Left wrapWithParentPathConstraint mostly as-is: > I evaluated using the new getFieldQuery here, but for the non-MatchAllDocsQuery path, forcing the new method would have required nesting a structured BooleanQuery ([+MatchAllDocsQuery, -ExistenceQuery]) inside a FILTER or MUST clause. This would have introduced an unnecessary extra layer to Lucene's internal query tree structure. Keeping the flat .add(newNestPathExistsQuery(), Occur.MUST_NOT) here keeps the execution path flat and fast, matching Lucene's design patterns perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:index cat:schema cat:search documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants