1

Does solr support nested documents? 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? 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.

0

2 Answers 2

4

Newer versions of Solr provides support for Nested Documents

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". 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. After indexing this Json if we query

"*":"*"

We should see 4 documents in all. Now we can get parent or child documents with the help of Block and join query parsers. 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
3
  • There is some error in your json format. There should be a "[" after "childDocuments": Oct 26, 2015 at 12:46
  • @Lijo: thnks..I changed it.
    – Gunjan
    Oct 27, 2015 at 4:35
  • :- If I want to index like below in solr,How can I do it? [{ "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", "cat_name": "sports" } ] Oct 28, 2015 at 5:05
3

No, Solr doesn't support that nested structure. Have a look at this other question too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.