【问题标题】:solr index nested documentsolr 索引嵌套文档
【发布时间】:2012-08-23 01:55:10
【问题描述】:

solr 是否支持嵌套文档?有没有更好的方法来实现这种文档?

<doc>
    <field name="name">Mr. Test</field>
    <field name="case">
        <field name="link">http://foo.com</field>
        <field name="date">1-2-1234</filed>
        <field name="title">My title</filed>
    </field>
    <field name="case">
        <field name="link">http://foo.com/2/</field>
        <field name="date">1-2-1234</filed>
        <field name="title">My title 2</filed>
    </field>
</doc>

我所拥有的是一个参与过多个案件的人。这种形式的模式对于 solr 是否合法?不同的人也可以是同一案件的一部分。所以它看起来确实像一个关系数据库的任务,但我在这个项目中使用了 solr。

【问题讨论】:

    标签: xml solr indexing


    【解决方案1】:

    较新版本的 Solr 提供对嵌套文档的支持

    索引这个 Json

    [
      {
        "id": "1",
        "title": "Solr adds block join support",
        "content_type": "parentDocument",
        "_childDocuments_": [
          {
            "id": "2",
            "comments": "SolrCloud supports it too!"
          }
        ]
      },
      {
        "id": "3",
        "title": "Lucene and Solr 4.5 is out",
        "content_type": "parentDocument",
        "_childDocuments_": [
          {
            "id": "4",
            "comments": "Lots of new features"
          }
        ]
      }
    ]
    

    在 schema.xml 中,您必须添加此处使用的所有字段,即“title”、“content_type”、“cmets”。参数 "childDocuments" 是 solr 处理的参数,它通过它理解这是一个子文档,而 "content_type": "parentDocument" 是 solr 理解这是父文档的标识符。如果我们查询,在索引这个 Json 之后

    "*":"*"
    

    我们应该总共看到 4 个文档。现在我们可以在Block and join query parsers 的帮助下获取父或子文档。试试这个查询

    http://localhost:8983/solr/collection_test/select?q={!child%20of=%22content_type:parentDocument%22}title:lucene
    

    还有这个

    http://localhost:8983/solr/collection_test/select?q={!parent%20which=%22content_type:parentDocument%22}comments:SolrCloud
    

    【讨论】:

    • 您的 json 格式有一些错误。在“childDocuments”之后应该有一个“[”:
    • @Lijo:谢谢..我改了。
    • :- 如果我想在 solr 中像下面这样索引,我该怎么做? [{“id”:“1”,“company_id”:“1”,“company_name”:“company_1”,“meta_categories”:[{“cat_id”:“1”,“cat_name”:“fashion”},{ “cat_id”:“2”,“cat_name”:“sports”}],“main_categories”:[{“cat_name”:“1”,“cat_name”:“fashion”},{“cat_name”:“2”, “猫名”:“运动”}]
    【解决方案2】:

    不,Solr 不支持这种嵌套结构。也可以看看this other question

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-05
      • 2011-05-27
      • 2019-02-21
      相关资源
      最近更新 更多