Skip to content

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

Open
abumarjikar wants to merge 9 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 9 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.

@@ -0,0 +1,7 @@
title: Add root document query shortcut support to NestPathField
type: changed

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.

This isn't "changed" since no existing user/query is going to trigger this functionality. The functionality here is opt-in, hence "added". If you think the changelog template could be improved here, LMK.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dsmiley Thanks for pointing out. I will update this to added.

Regarding the changelog types— I think adding a quick cheat-sheet directly into dev-docs/changelog.adoc would be awesome for developers trying to pick between added, changed, or other on the fly.

I can open a quick separate PR to add a small reference table there if you think it's a good idea!

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 on lines +2005 to +2007
try (SolrQueryRequest req = req("df", "_nest_path_")) {
assertQueryEquals(null, req, "{!field f=_nest_path_ v=''}", "{!field f=_nest_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.

this tests that these two are equivalent but not what they are equivalent to -- the boolean query with matchAll docs negated by an existence query

@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

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.

What I meant was that you search the whole ref guide for _nest_path_ and see if that specific reference is a usage example that can be simplified due to your change. Hint: they exist. I also strongly suspect some tests are doing this but didn't check.

In the past, we sometimes add better ways to do things but didn't do the work of updating Solr to actually leverage what was added. As a consequence, that wasn't helpful: people/LLMs don't know what they don't see used.

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