Reputation: 100
I'm looking to setup a Solr search system which returns only top level records but also searches across the children (returning their parent record).
I'm running Solr 8.8.1 with a sample of the schema as follows
<field name="solr_type" type="string" indexed="true" stored="true" />
<field name="path" type="string" indexed="true" stored="true" />
<field name="_root_" type="string" indexed="true" stored="false" docValues="false" />
<fieldType name="_nest_path_" class="solr.NestPathField" />
<field name="nest_path" type="_nest_path_" />
And a sample parent/child record like this, noting that some records have no children
{
"dc_identifier_s": "41ef95d3cbc8473888d1734412bf82f0-4",
"dc_title_s": "CRB_Hydrologic",
"solr_type":"parent"
"_childDocuments_": [
{
"dc_identifier_s": "41ef95d3cbc8473888d1734412bf82f0_0-4",
"dc_title_s": "CR HUC1"
"solr_type":"child"
}]
}
I've been following the instructions here (https://solr.apache.org/guide/8_0/searching-nested-documents.html) but as 'nest_path' doesn't populate, I've opted to use a custom field 'solr_type' which I set to either 'parent' or 'child'
Any guidance in how to search across all records but restrict results to the top level and the parents of child records would be much appreciated.
Thanks
Upvotes: 1
Views: 1393
Reputation: 4141
You want the root documents, but to find (search) based on matches in child documents, and perhaps matches in root docs too? This is a straight-forward application of the "parent" query parser as described in the guide; something like this:
&q={!parent which="*:* -_nest_path_:*" v=$q.nest}
&q.nest=real user query goes here
You didn't characterize what your queries otherwise like (what would go in q.nest above; an arbitrary named param I made up) -- maybe edismax or who knows what. If you need to restrict matches to certain documents (say simple field=value or spatial maybe), you'll need to compose a more interesting query in there; you can't use filter queries (fq
) because filter queries filter documents that q
matches, which is only root documents. So q.nest
might be something like +{!geofilt} +field:value +{!edismax v=$q.user}
I recommend using a more recent version of Solr than 8.0 (you refer to 8.0 docs) but I believe 8.0 will work nonetheless. I especially don't advise earlier versions for nested docs.
Upvotes: 1