Solr Json Facet API

By Chakravarthy Yeleswarapu 2 min read

I’d start off my Solr blog series with Json facet API. Because this API is watershed between Solr 4.x and Solr 5.x versions. Prior to Solr 5.x statistics/analytics capability was done using stats component this included facet capabilities. However, using stats and faceting was kludgy and inefficient. What I mean by this is, for example, consider following json structure.

Solr-Json-facet_API

You’d want to facet by category, sub-facet by inStock and along the way obtain price statistics such as min/max.

We could use Solr’s stats & pivoting component to achieve this.

1

2

3

4

5

http://localhost:8983/solr/techproducts/select? q=*:*&

stats=true&

stats.field={!tag=piv1 min=true max=true}price&

facet=true&

facet.pivot={!stats=piv1}category,inStock

Depending on the number of documents, the above query will be in the order of seconds, which does not help many use cases. For web reporting application that respond to user’s clicks, this sort of latency in seconds may be unacceptable.

This is where Json facet API comes in handy. The above facet-pivoting query can be rewritten using this new API as follows.

Find top 5 categories and return number of products in-stock and out-of-stock
Solr-Json-facet-API
Similarly, to Find top 5 categories and return manufacturers under each category just change field:manu

Solr-Json-facet-API

Above approach has several advantages.

  1. The QTime for this query, even for millions of records would be in milliseconds.
  2. The query formation is quite intuitive, because json structure provides clarity when compared to local tags used in facet-pivoting approach.
  3. Applications can programmatically manipulate json.facet structure at runtime, possibly responding to user clicks.
  4. Each json.facet structure can be logically maintained per use case, separate from the Solr query and combined together at runtime.
  5. For Java based API implementations, Solrj client library has great support in SolrCloud mode as well.

The only caveat is, if cardinality of field values (or unique values in each field) exceeds 100 per shard, then estimation algorithm kicks in. There is already a Jira for this issue that could be addressed in future releases.

Update: There is a patch committed for Jira. Perhaps this should rollout in version 6.5 or so.

Explore Additional Resources

Learn how you can select the best Digital Experience platform for your business.

If you’d like to learn more about Adobe Experience Manager, visit our Adobe Practice.


GET HELP FROM OUR EXPERTS

Over the past 19 years, we have completed thousands of digital projects globally. We have one of the largest and deepest multi-solutions digital consulting teams in the world. Our proprietary processes and years of Digital Experience expertise have earned us a 97% customer satisfaction rating with our clients ranging from Global Fortune 1000 to Mid-Market Enterprises, leading educational institutions, and Non-Profits.

Contact us if your organization needs assistance with Solr search.

About TA Digital

TA Digital is the only global boutique agency that delivers the “best of both worlds” to clients seeking to achieve organizational success through digital transformation. Unlike smaller, regional agencies that lack the ability to scale or large organizations that succumb to a quantity-over-quality approach, we offer resource diversity while also providing meticulous attention to the details that enable strategic success.

Over the past 20 years, TA Digital has positioned clients to achieve digital maturity by focusing on data, customer-centricity and exponential return on investment; by melding exceptional user experience and data-driven methodologies with artificial intelligence and machine learning, we enable digital transformations that intelligently build upon the strategies we set into motion. We are known as a global leader that assists marketing and technology executives in understanding the digital ecosystem while identifying cultural and operational gaps within their business – ultimately ushering organizations toward a more mature model and profitable digital landscape.

Recognized in 2013, 2014, 2015, and 2019 Inc. 5000 list as one of the most successful technology companies in the United States, TA Digital is pleased also to share high-level strategic partnerships with world class digital experience platform companies like Adobe, SAP and Salesforce and possess global partnerships with industry leaders such as Sitecore, Episerver, Elastic Path, BigCommerce, AWS, Azure and Coveo.

Chakravarthy Yeleswarapu

Written By

Chakravarthy Yeleswarapu

More Blogs by the author

SolrCloud setup on Mac
SolrCloud setup on Mac Chakravarthy Yeleswarapu 3 min read
Zookeeper Ensemble of 3 Nodes On Mac
Zookeeper Ensemble of 3 Nodes On Mac Chakravarthy Yeleswarapu 3 min read