Solr documents with child elements?

cambo picture cambo · Apr 7, 2011 · Viewed 30.5k times · Source

Is it somehow possible to create a solr document that contains sub-elements?

For example, how would I represent something like this:

<person first="Bob" last="Smith">
   <children>
      <child first="Little" last="Smith" />
      <child first="Junior" last="Smith" />
   </children>
</person>

What is the usual way to solve this problem?

Answer

whomer picture whomer · Oct 13, 2014

As of Solr 4.7 and 4.8, Solr supports nested documents:

{
"id": "chapter1",
"title" : "Indexing Child Documents in JSON",
"content_type": "chapter",
"_childDocuments_": [
  {
    "id": "1-1",
    "content_type": "page",
    "text": "ho hum... this is page 1 of chapter 1"
  },
  {
    "id": "1-2",
    "content_type": "page",
    "text": "more text... this is page 2 of chapter 1"
  }
]
}

See the Solr release notes for more.