【问题标题】:Solr Nested Documents: Can't make non-anon nested documents (_nest_path_) workSolr 嵌套文档:无法使非匿名嵌套文档 (_nest_path_) 工作
【发布时间】:2022-08-19 00:44:54
【问题描述】:

我正在尝试使用非匿名嵌套类创建索引。我想要的 solr 输出是:

 \"responseHeader\":{
    \"status\":0,
    \"QTime\":8,
    \"params\":{
      \"q\":\"discriminator:project\",
      \"indent\":\"true\",
      \"fl\":\"*,[child]\",
      \"q.op\":\"OR\",
      \"_\":\"1660714908720\"}},
  \"response\":{\"numFound\":1003,\"start\":0,\"numFoundExact\":true,\"docs\":[
        {\"name\":\"Project 1\",
        \"id\":\"315500\",
        \"discriminator\":\"project\",
        \"_version_\":1741444763087798272,
        \"publicContacts\":[
        {
          \"name\":\"Gurney Halleck\",
          \"id\":\"315520\",
          \"discriminator\":\"publicContact\",
          \"_version_\":1741444763087798272},
        {
          \"name\":\"Thufir Hawat\",
          \"id\":\"315530\",
          \"discriminator\":\"publicContact\",
          \"_version_\":1741444763087798272}]},

我已阅读并关注:https://solr.apache.org/guide/8_0/indexing-nested-documents.htmlhttps://solr.apache.org/guide/8_11/indexing-nested-documents.html#indexing-nested-documents

如果我添加 /just/

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

在我的 schema.xml 中,我可以执行查询并获得返回匿名嵌套文档的结果子文档

 \"responseHeader\":{
    \"status\":0,
    \"QTime\":8,
    \"params\":{
      \"q\":\"discriminator:project\",
      \"indent\":\"true\",
      \"fl\":\"*,[child]\",
      \"q.op\":\"OR\",
      \"_\":\"1660714908720\"}},
  \"response\":{\"numFound\":1003,\"start\":0,\"numFoundExact\":true,\"docs\":[ 
        \"name\":\"Project 1\",
        \"id\":\"315500\",
        \"discriminator\":\"project\",
        \"_version_\":1741444763087798272,
        \"_childDocuments_\":[
        {
          \"name\":\"Gurney Halleck\",
          \"id\":\"315520\",
          \"discriminator\":\"publicContact\",
          \"_version_\":1741444763087798272},
        {
          \"name\":\"Thufir Hawat\",
          \"id\":\"315530\",
          \"discriminator\":\"publicContact\",
          \"_version_\":1741444763087798272}]
        },

但是,如果我添加

<fieldType name=\"_nest_path_\" class=\"solr.NestPathField\" />
<field name=\"_nest_path_\" type=\"_nest_path_\" stored=\"true\" />

根本没有创建嵌套关系(甚至没有创建匿名 childDocuments!),但是我的下一个文档被放入索引中。

我正在使用 DIH 来索引文档:

        <entity transformer=\"RegexTransformer\" name=\"project\" query=\"select * from project\">
            <!-- universal fields -->
            <field column=\"discriminator\"/>
            <field column=\"id\"/>
            <field column=\"name\"/>

            <entity child=\"true\" name=\"publicContacts\" query=\"select * from project_public_contacts where project_id=\'${project.id}\'\">
                <field column=\"discriminator\"/>
                <field column=\"id\"/>
                <field column=\"name\"/>
            </entity>
        </entity>

我究竟做错了什么?

    标签: solr


    【解决方案1】:

    在深入研究之后,我发现这是 Solr 的 DIH 中的一个缺陷。截至 2020 年 8 月 29 日,Apache 已确定由于 DIH 的弃用,此缺陷将不会被修复。

    https://issues.apache.org/jira/browse/SOLR-14490?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel

    我确实找到了解决方法,即填充嵌套路径自己在 db-data-config.xml 中。例如:

            <entity name="project" query="select * from project">
                <!-- universal fields -->
                <field column="discriminator"/>
                <field column="id"/>
                <field column="name"/>
    
                <entity child="true" name="publicContacts" query="select * from project_public_contacts where project_id='${project.id}'">
                    <field column="discriminator"/>
                    <field column="id"/>
                    <field column="name"/>
                    <field column="nest" name="_nest_path_"/>
                </entity>
    
                <entity child="true" name="privateContacts" query="select * from project_private_contacts where project_id='${project.id}'">
                    <field column="discriminator"/>
                    <field column="id"/>
                    <field column="name"/>
                    <field column="nest" name="_nest_path_"/>
                </entity>
            </entity>
    

    值如下所示:

    /publicContacts
    

    或任何您想要命名该属性的名称。有关_nest_path_ 字段应设置为的方式/内容的更多详细信息,您可以将该字段设置为存储在 schema.xml 中,然后使用 SOLR REST 端点或其他非 DIH 方式填充数据以查看它的情况人口稠密。这就是我调试此问题的方式。

    <field name="_nest_path_" type="_nest_path_" stored="true"/>
    

    我还注意到我在原始帖子中提供的 SOLR 链接中的文档不正确。您确实需要在 schema.xml 中为命名的子文档定义字段。尝试在没有它们的情况下通过 REST 端点建立索引时收到错误。我的定义是:

    <field name="publicContacts" type="string" indexed="true" stored="true" required="false" multiValued="true"/>
    <field name="privateContacts" type="string" indexed="true" stored="true" required="false" multiValued="true"/>
    

    【讨论】:

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