Grouping documents by the field value

Imagine a situation where your dataset is divided into different categories, subcategories, price ranges, and things like that. What if you would like to not only get information about counts in such groups (with the use of faceting), but you would only like to show the most relevant document in each of the groups. In such cases, a Solr grouping mechanism comes in handy. This recipe will show you how to group your documents on the basis of the value of the field.

How to do it...

  1. Let's start with the index structure. Let's assume that we have the following fields in our index (just add the following section to the schema.xml file):
    <field name="id" type="string" indexed="true" stored="true" required="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.