Handling hierarchies with nested documents

In the real world, data is not flat, it contains many hierarchies that we need to handle. Sometimes it is not possible to flatten the data, but still we want to avoid cross and false matches. For example, let's assume that we have articles and comments to these articles, for example, news sites or blogs. Imagine that we want to search for articles and comments at the same time. To do this, we will use the Solr nested documents; this recipe will show you how to do this.

How to do it...

To handle hierarchies with nested documents, follow these steps:

  1. We start by defining the index structure. To do this, we add the following fields to our schema.xml file:
    <field name="id" type="string" indexed="true" stored="true" ...

Get Solr Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.