Home Insights Searching grandchildren and siblings with Solr block join

Searching grandchildren and siblings with Solr block join

Searching grandchildren and siblings with Solr Block Join

We’ve talked about searching nested parents and children with Solr Block Join. But we can go far beyond that, to searching siblings, grandchildren, and other descendants. This gives your customers more search options without forcing them to do a new search every time they add a search parameter.  In fact, with Solr Block Join, nesting depth and search option possibilities are almost unlimited, so your customers can see more of what you have to offer with fewer clicks than it would take without Block Join. Here’s how it works:

Let’s take Solr 4.5 or above and index the data. The data structure here is a bit more complex than some examples we’ve seen, so it’s worth a diagram:

more elaborate ecommerce data model which includes grandchildren and sibling relations

As you can see, this hierarchical structure is similar to entity-relationship models from the RDBMS world. We name those nested entities “scopes.”
Once data is indexed, use q=*:*&wt=csv&rows=100 to see how the documents are aligned in blocks.

Let’s consider a search for a t-shirt product (parent) which has a particular SKU (child) that has sufficient inventory available in a particular storage location. We model a storage location as a child of the SKU scope, and a grandchild of the product scope.

Here is a search for t-shirts, of which have sufficient inventory (>10) of Blue XL SKUs in CA:

q={!parent which=type_s:product}+COLOR_s:Blue +SIZE_s:XL +{!parent which=type_s:sku v='+QTY_i:[10 TO *] +STATE_s:CA'}

Here’s a trick recommended by  David Smiley; when a child query contains a space you need to wrap it into {!… v=’..’} local parameter, or extract it into a separate request parameter and refer to it by {!… v=$ref}…&ref=…&.

You can see that a crossmatch is excluded; this query returns products 20 and 30. You can remove either QTY_i filter or COLOR_s, which brings product 10 into the results.
Needless to say, possible nesting depth is unlimited. One more interesting observation about Block Join is that it provides blazing-fast transitive closure on parent-child relationships: you can search for grandchildren and deeper descendants directly, omitting queries for intermediate scopes.

Sibling scopes

Vendor and SKU scopes share the same parent product and are not nested in each other.
Let’s search for t-shirts which are made by Vendor Bob and cost between $20 and $25. Here, a local parameter reference is necessary:

q=+{!parent which=type_s:product v=$skuq} +{!parent which=type_s:product v=$vendorq}&skuq=+COLOR_s:Blue +SIZE_s:XL +{!parent which=type_s:sku v='+QTY_i:[10 TO *] +STATE_s:CA'}&vendorq=+NAME_s:Bob +PRICE_i:[20 TO 25]

As you can see, it returns only product 20, and if you relax the query, e.g. choose vendor Alice or accept more expensive t-shirts, product 30 appears. It works like relational calculus!

If you have a question about Block Join in Solr, please post a comment below or contact us via email.

Tags

You might also like

Isometric visualization of AI-powered data flows connecting enterprise product catalog systems
Article
Six reasons your product catalog needs a makeover in 2026—and how to get it right
Article Six reasons your product catalog needs a makeover in 2026—and how to get it right

Once upon a time, your enterprise product catalog was a backend concern. A necessary system of record. Something teams updated quietly while the real “experience” work happened elsewhere. Today, that separation no longer exists. Research shows that 87% of shoppers rate product data as “extremely...

Distributed computing infrastructure with interconnected blocks and data streams in red, green, and amber, representing the hybrid deep learning architecture connecting cloud-based Azure Databricks with on-premises NVIDIA DGX systems for deep learning workloads.
Article
Hybrid deep learning with Azure Databricks and on-prem NVIDIA DGX
Article Hybrid deep learning with Azure Databricks and on-prem NVIDIA DGX

Modern enterprises increasingly rely on deep learning to power mission-critical workflows such as global demand forecasting, inventory optimization, supply chain prediction, video-based defect detection, and financial risk modeling. These workloads demonstrate rapidly increasing GPU requirements, g...

AI demand forecasting model comparison visualization showing pixelated human figures with data blocks representing Time Series Foundation Models and predictive analytics
Article
Time-series foundation models: AI demand forecasting comparison
Article Time-series foundation models: AI demand forecasting comparison

Predictive analytics is undergoing a major transformation. This AI demand forecasting model comparison reveals significant performance gaps between traditional and modern approaches. Demand forecasting has long guided decisions in retail and manufacturing, but today’s data volumes and volatility ar...

Stylized shoppers and digital devices illustrating agentic payments.
Article
What the ACP vs AP2 agentic payments comparison means for you
Article What the ACP vs AP2 agentic payments comparison means for you

Agentic commerce is in the midst of a defining moment. Instead of a customer navigating a checkout flow, AI shopping agents can now autonomously purchase goods, renew subscriptions, or restock supplies, executing payments entirely on the customer’s behalf through agentic payments protocols. It’s...

Inventory management system featuring a central storefront surrounded by delivery vans, shopping carts, stacked packages, and digital screens. The scene depicts the integration of online and physical retail, logistics, and automated inventory processes, all connected within a seamless, technology-driven supply chain
Article
Beyond multichannel: The competitive edge of omnichannel order management
Article Beyond multichannel: The competitive edge of omnichannel order management

You know the feeling: you walk into a store only to find out that the product you saw online is out of stock! This is one of the most common and problematic experiences for customers who shop multichannel retail. The problem for you? Disconnected sales channels, lost income, frustrated custom...

A shopping cart surrounded by silhouetted people in a vibrant, digital marketplace with hexagonal icons floating above, representing B2B composable commerce.
Article
Composable commerce for B2B: Overkill or delivers big?
Article Composable commerce for B2B: Overkill or delivers big?

The buzzword “composable commerce” has dominated digital strategy conversations since Gartner popularized the term in 2020. But behind the marketing hype lies a longstanding, proven practice of integrating specialized, best-of-breed technology components into a flexible and scalable ecosystem....

Multicolor whisps of smoke on a black background
Article
Headless CMS for the AI era with Grid Dynamics, Contentstack, and Google Cloud
Article Headless CMS for the AI era with Grid Dynamics, Contentstack, and Google Cloud

For many businesses, moving away from familiar but inherently unadaptable legacy suites is challenging. However, eliminating this technical debt one step at a time can bolster your confidence. The best starting point is transitioning from a monolithic CMS to a headless CMS. This shift to a modern c...

Let's talk

    This field is required.
    This field is required.
    This field is required.
    By sharing my contact details, I consent to Grid Dynamics process my personal information. More details about how data is handled and how opt-out in our Terms & Conditions and Privacy Policy.
    Submitting

    Thank you!

    It is very important to be in touch with you.
    We will get back to you soon. Have a great day!

    check

    Thank you for reaching out!

    We value your time and our team will be in touch soon.

    check

    Something went wrong...

    There are possible difficulties with connection or other issues.
    Please try again after some time.

    Retry