I am trying to create a solr document with a child document. I am using solr 8.2.0 In order to comply with the instructions in https://lucene.apache.org/solr/guide/8_0/indexing-nested-documents.html#indexing-nested-documents , I added the following to schema.xml
<field name="_root_" type="string" indexed="true" stored="false"/>
<fieldType name="nest_path" class="solr.NestPathField" />
<field name="_nest_path_" type="nest_path" />
<field name="_nest_parent_" type="string" indexed="true" stored="true"/>
To create a test document, I used the following PHP code:
$solrClient = ...
$solrInputDocument = new SolrInputDocument();
$solrInputDocument->addField('id', 'yirmi1', 1);
$solrInputDocument->addField('test_s', 'this is a parent test', 1);
$childDoc = new SolrInputDocument();
$childDoc->addField('id', 'yirmi2', 1);
$childDoc->addField('test_s', 'this is a child test', 1);
$solrInputDocument->addChildDocument($childDoc);
$solrUpdateResponse = $solrClient->addDocument($solrInputDocument);
$solrClient->commit();
When I query for fq=id: "yirmi1"
or fq=id: "yirmi2"
,
the records come up, but there is no indication that there are parent or child documents. Also, when querying for the fields _nest_parent_
, _nest_path_
, and _root_
do not come up, even when I specify them as query fields.
What else do I have to set up to properly create nested documents.
Apparently "anonymous" or "unlabelled" child documents and _nest_path_
do not mix well together.
I think you have 2 options:
A)
If you want to use addChildDocument, you will need to remove _nest_path_
and _nest_parent_
fields from your schema.
B)
Set the parent-child relation like you would set any other field:
$solrInputDocument->addField('child', $childDoc);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With