Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The Solr JSON Facet API groups documents that match a query into buckets, then returns counts and optional statistics for those buckets. The key to reading any result correctly is its domain: the set of documents eligible to contribute. Nested facets let you ask a follow-up question inside each bucket, while distributed-search settings affect which top terms are collected and how accurately returned buckets are refined.

What is the Solr JSON Facet API?

Faceted search helps people narrow a result set by categories such as product type, manufacturer, or price range. Solr facets perform that grouping over matching documents and report counts; JSON Facet API expresses the request as a structured JSON object and returns a structured response.

Facets can produce buckets or summarize values. Terms and range facets can create multiple buckets; query and heatmap facets each produce a single bucket. Statistics such as averages can accompany these results.

The examples below follow the Apache Solr Reference Guide. The guide’s latest JSON Facet API reference is rolling documentation, so check the guide for the Solr version you actually deploy before relying on syntax or defaults. A Solr 9.0 guide also documents the API’s statistics and domain model.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I add a terms facet to a Solr query?

A terms facet groups matching documents by the indexed value of a field. This example asks for up to five category buckets:

{
  "query": "*:*",
  "facet": {
    "categories": {
      "type": "terms",
      "field": "cat",
      "limit": 5
    }
  }
}

Here, field identifies the field to group by and limit caps the number of buckets returned. The default terms-facet ordering is count descending. If an application needs a different result order or paging, review sort and offset; if it needs control over low-count or missing-value buckets, review mincount and missing. The guide also documents numBuckets, allBuckets, and collection-method selection.

Choose those controls to match the interface: for example, a paged category list needs deliberate ordering and an offset, while a filter menu may need to decide whether zero-count or missing-value entries belong. A limit controls the returned list; it does not mean that Solr returns every possible term.

What does a facet domain include?

A facet’s domain is the set of documents allowed to contribute to its buckets or statistics. A top-level facet normally operates on documents matching the main query. A nested facet normally operates on the documents assigned to its parent bucket. The JSON Facet API’s domain property can filter, expand, or replace the starting set before a partitioning facet runs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. The query selects the starting documents. A query such as *:* matches all documents in the applicable collection, subject to request filters and other query context.
  2. A parent facet partitions that set. A terms facet on cat, for example, places matching documents into category buckets.
  3. A child facet asks a new question within a partition. Its counts and statistics are based on documents in that parent bucket unless a domain change alters them.

The reference guide also documents domain transformations for parent/child relationships in nested documents. Domain changes apply to facets that partition data; a *:* query facet with a domain change can also act as a grouping point for sub-facets. When a count looks unexpected, check the main query, filters, indexed field values, and any domain transformations before treating the aggregation as faulty. See the guide’s domain changes reference for the supported transformations.

How do nested facets work?

A sub-facet is an aggregation attached to a parent facet. Solr evaluates it within each parent bucket, so one request can answer both “Which categories have the most products?” and “Who is the leading manufacturer in each category?”

Conceptually, the response has a category bucket containing its count and a nested manufacturer facet; that inner facet contains manufacturer buckets and counts for that category. The manufacturer counts therefore describe products assigned to that particular category, not the entire query result set. This hierarchy can be rendered by a client without sending a separate query for every category.

The exact response includes facet metadata as well as bucket data. Build the client around the documented response shape for the deployed Solr version, rather than assuming the nested buckets are interchangeable with top-level results.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I get statistics for each facet bucket?

Bucket counts tell you how many documents belong to a group. Statistical facets summarize field values over a domain or bucket. For example, a category result can include an average price, a unique supplier count, or the 50th percentile of weight. This gives a search interface context beyond the number of matching documents.

Keep the two roles distinct: a facet partitions documents, while a metric describes values across the documents in the relevant domain. The official guide demonstrates functions including avg, unique counts, and percentiles. Confirm the supported functions and field requirements in the documentation for your Solr release before implementing a metric.

What matters for distributed terms facets?

In a distributed search, shards collect local term buckets. A term that ranks highly across the whole collection may not be a local leader on every shard, so simply combining each shard’s first choices can miss buckets or leave returned values incomplete. The JSON Facet API documents controls for this collection and refinement process:

  • overrequest asks shards for extra candidate buckets internally. This can improve the final top-term selection when shard-local leaders differ from global leaders.
  • refine can retrieve buckets needed for the final result from shards that did not return them in the initial collection. The guide describes refinement as making counts and statistics exact for returned buckets.
  • overrefine provides an additional control over refinement candidates, as documented in the terms-facet reference.

These controls address collection and accuracy for returned buckets; they do not override limit or promise that every possible bucket will be returned. The guide also lists collection methods dv, uif, dvhash, enum, stream, and smart, with smart as the default. Method choice depends on the field and workload, so treat it as an implementation option to evaluate rather than a universal tuning rule.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When should I use JSON faceting instead of traditional faceting?

Traditional faceting remains documented in Solr, including parameters such as facet.field, facet.query, facet.limit, facet.sort, and range-facet controls. The choice is chiefly about request structure, nesting, metrics, and how the client consumes the response—not a universal speed advantage.

Consideration JSON Facet API Traditional faceting
Request structure Structured JSON object for expressing facets and sub-facets. Uses parameters such as facet.field and facet.query.
Nested breakdowns Supports sub-facets that calculate a follow-up aggregation within each parent bucket. Does not offer the same documented JSON nesting structure.
Metrics Supports statistics and analytics alongside buckets. Use when its facet parameters meet the request; compare requirements against the JSON API’s metric capabilities.
Response and client parsing Returns facets in a structured response suited to programmatic handling. Uses the traditional faceting response conventions that the client must parse.
Performance No universal advantage is established; behavior depends on workload and configuration. No universal advantage is established; behavior depends on workload and configuration.

Prefer JSON faceting when the application benefits from a unified structured request, nested breakdowns, or bucket-level metrics. Traditional faceting remains reasonable when its parameter-based structure already fits the task and client. Test the actual query shape and data distribution on the deployed Solr version if performance is a deciding factor; the API choice alone does not establish which will be faster.

The Reference Guide marks the Analytics Component deprecated and directs users toward similar functionality in JSON Facet API. That is migration context, not evidence that every Analytics use case has a drop-in replacement. Compare the specific functions an application uses with the Analytics Component reference, and notify the Solr project if required functionality is not covered.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.