Reputation: 623
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.
Upvotes: 5
Views: 1982
Reputation: 1982
For me (Solr 8.5.1, documents added via Data Import Handler with nested entities from PostgreSQL) the _childDocuments_
are only included in the response if the schema.xml does not contain the _nest_path_
field and field type.
_nest_parent_
can be removed from the schema as well, since it is not populated as far as I observed.
A _root_
field is required in the schema:
<field name="_root_" type="string" indexed="true" stored="true" docValues="false" />
It worked best by adding some sort of type information to the documents, e.g. entitytype
as in the following example:
...
$solrInputDocument = new SolrInputDocument();
$solrInputDocument->addField('id', 'yirmi1', 1);
$solrInputDocument->addField('entitytype', 'parent', 1);
$solrInputDocument->addField('test_s', 'this is a parent test', 1);
$childDoc = new SolrInputDocument();
$childDoc->addField('id', 'yirmi2', 1);
$childDoc->addField('entitytype', 'child', 1);
$childDoc->addField('test_s', 'this is a child test', 1);
$solrInputDocument->addChildDocument($childDoc);
...
and then querying with the following parameters:
q=entitytype:parent
fl=*,[child parentFilter=entitytype:parent]
Upvotes: 0
Reputation: 2009
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);
Upvotes: 2
Reputation: 459
Have you added fl=*,[child]
?
That should return childDocuments .
I will admit that I'm new to SOLR and I haven't had 100% success with this. :(
Upvotes: 0