Goal
Enable indexing and querying of nested documents in Solr and Fusion such that all fields from both parent and child documents are searchable, but child documents are only returned within their parent and not as separate top-level results.
Environment
Fusion 5.8.1 and above
Solr 9.1.1 and above
Applies to both Solr-only and Fusion deployments.
Guide
Understand nested documents and search behaviour
- Solr supports nested documents using the
_childDocuments_field within a parent document. - To ensure proper indexing and query results, All fields should be searchable unless explicitly excluded (for example, set
indexed="false"in schema). - For atomic updates and child document modifications, ensure all fields involved are marked with
stored="true"in your Solr schema.
Indexing in Fusion: preserve nested structure
Fusion flattens nested documents by default. To retain structure, choose one of the following options:
-
Option 1: Use a custom JavaScript stage in your index pipeline to preserve the
_childDocuments_structure before reaching Solr. - Option 2: Bypass Fusion’s indexing and post directly to Solr’s update handler.
Sample data structure
Index parent documents with child documents using _childDocuments_, for example:
{
"id": "1",
"positionName_t": "Software Engineer",
"clientId_t": "test2",
"_childDocuments_": [
{
"displayName_t": "Bob",
"clientId_t": "test2"
},
{
"displayName_t": "Thomas Doe",
"clientId_t": "test2"
}
]
}
Ensure that the Solr schema supports the fields used and that clientId_t is not indexed if it should be excluded from searches.
Prevent top-level return of child documents
By default, querying without filters may return child documents as standalone results. Use the following filter to suppress standalone child documents:
fq=NOT _nest_path_:*Example full query:
q=doe&fq=clientId_t:test2&fq=NOT _nest_path_:*&fl=*,score,[child]This filter works because child documents have a _nest_path_ field while parent documents do not.
Search both parent and child content
To ensure a search term matches either parent or child content and returns the full parent block with children, use a block-join query:
q=(searchTerm OR {!parent which='*:*'} searchTerm)&fq=NOT _nest_path_:*&fl=*,score,[child]This syntax searches both levels while limiting results to top-level parent documents. Replace searchTerm with the desired term and refine the which clause as needed for your schema.
Expected scoring behavior
Solr applies scoring to the parent document. Child documents returned via [child] transformer do not receive individual scores and will show a score of 0.0. This is expected behavior.
References
Refer to these Solr resources for deeper understanding:
- Indexing Nested Documents
- Searching Nested Documents
- Block Join Query Parser
- ChildDocTransformerFactory
If further customization is needed beyond these approaches, consult your Technical Success or Professional Services team for implementation support.