Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr Nested Documents not properly setup

Tags:

solr

solr8

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.

like image 215
Yirmiyahu Fischer Avatar asked Nov 07 '22 10:11

Yirmiyahu Fischer


1 Answers

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);
like image 141
Mico Avatar answered Nov 15 '22 08:11

Mico