简体   繁体   English

Solr索引嵌套文档

[英]solr index nested document

Does solr support nested documents? Solr是否支持嵌套文档? And is there a better way to achieve this sort of document? 有没有更好的方法来实现此类文档?

<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>

What I have is a person that has been part of multiple cases. 我所拥有的人是多个案件的一部分。 Is this form of schema legal with solr? 这种形式的架构对solr合法吗? A different person can also be part of the same case. 不同的人也可以属于同一案件。 So it does look like a task for a relational database, but I'm using solr for this project. 因此,它看起来确实像是关系数据库的任务,但是我在该项目中使用solr。

No, Solr doesn't support that nested structure. 不,Solr不支持该嵌套结构。 Have a look at this other question too. 也看看其他问题

Newer versions of Solr provides support for Nested Documents 较新版本的Solr提供对嵌套文档的支持

Index this 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"
      }
    ]
  }
]

Into schema.xml, u have to add all the fields which are getting used here that is "title","content_type","comments". 您必须在schema.xml中添加正在使用的所有字段,即“ title”,“ content_type”,“ comments”。 The parameter " childDocuments " is the parameter which solr takes care and with which it understands this is a child document and "content_type": "parentDocument" is the identifier for solr to understand that this is parent document. 参数“ childDocuments ”是solr会注意的参数,它可以理解为这是一个子文档,而“ content_type”:“ parentDocument”是solr的标识符,以了解这是父文档。 After indexing this Json if we query 在索引此Json后,如果我们查询

"*":"*"

We should see 4 documents in all. 我们应该总共看4个文件。 Now we can get parent or child documents with the help of Block and join query parsers . 现在,我们可以在Block的帮助下获取父文档或子文档, 并加入查询解析器 Try this queries 试试这个查询

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

and this one 还有这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM