【问题标题】:Solr Nested Documents not properly setupSolr 嵌套文档未正确设置
【发布时间】:2020-04-21 07:12:35
【问题描述】:

我正在尝试使用子文档创建 solr 文档。我正在使用 solr 8.2.0 为了遵守 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"fq=id: "yirmi2" 时, 记录出现了,但没有迹象表明有父文件或子文件。此外,当查询_nest_parent__nest_path__root_ 字段时,即使我将它们指定为查询字段,也不会出现。

我还需要设置什么才能正确创建嵌套文档。

【问题讨论】:

  • 嘿,添加子文档成功了吗?我也有同样的问题

标签: solr solr8


【解决方案1】:

显然“匿名”或“未标记”子文档和 _nest_path_ 不能很好地混合在一起。

我认为你有两个选择:

一)

如果您想使用 addChildDocument,您需要从架构中删除 _nest_path__nest_parent_ 字段。

B)

像设置任何其他字段一样设置父子关系:

$solrInputDocument->addField('child', $childDoc);

【讨论】:

  • 我尝试了使用 nest_path 和不使用 addChildDocument()addField('child') - 当查询返回父文档时仍然没有子文档的迹象。
  • 如果你想在结果中包含孩子,你需要使用 ChildDocTransformerFactory
  • $solrInputDocument->addField('child', $childDoc);这不起作用..我们在 php 中有什么解决方案吗?
【解决方案2】:

您添加了fl=*,[child] 吗? 那应该返回 childDocuments

我承认我是 SOLR 的新手,而且我还没有 100% 成功。 :(

【讨论】:

  • 这在这里不起作用。子文档仍未显示在父文档中。
【解决方案3】:

对我来说(Solr 8.5.1,通过数据导入处理程序添加的文档以及来自 PostgreSQL 的嵌套实体)只有在 schema.xml 不包含 _nest_path_ 字段和字段类型时,_childDocuments_ 才会包含在响应中。

_nest_parent_ 也可以从架构中删除,因为据我观察,它没有被填充。

架构中需要_root_ 字段:

<field name="_root_" type="string" indexed="true" stored="true" docValues="false" /> 

通过在文档中添加某种类型的信息效果最好,例如entitytype 如下例:

...
$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);
...

然后使用以下参数进行查询:

q=entitytype:parent
fl=*,[child parentFilter=entitytype:parent]

【讨论】:

    猜你喜欢
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    • 2015-11-01
    • 2017-03-22
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    相关资源
    最近更新 更多