我正在尝试使用子文档创建 solr 文档。我使用的是solr 8.2.0
为了遵守中的说明https://lucene.apache.org/solr/guide/8_0/indexing-nested-documents.html#indexing-nested-documents https://lucene.apache.org/solr/guide/8_0/indexing-nested-documents.html#indexing-nested-documents,我将以下内容添加到 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"/>
为了创建测试文档,我使用了以下 PHP 代码:
$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();
当我查询fq=id: "yirmi1"
or fq=id: "yirmi2"
,
记录出现了,但没有迹象表明有父文件或子文件。另外,查询字段时_nest_parent_
, _nest_path_
, and _root_
即使我将它们指定为查询字段,也不会出现。
我还需要设置什么才能正确创建嵌套文档。