Searching documents in Sanity Studio using references and filters
Yes, you can search for documents based on references in Sanity Studio! There are a few ways to do this:
Built-in Reference Field Search
When you're creating or editing a document with a reference field, Sanity Studio provides built-in search functionality. According to the Connected Content documentation, a reference field in the studio lets you "search and select a document you want to reference."
For example, if you have a movie document with a cast field that references actor documents, when you're editing a movie, you can search for and select actors like Tom Cruise directly in that reference field.
Reverse Reference Search (Finding Movies with Tom Cruise)
If you want to search backwards - finding all Movies that reference a specific Actor - you have several options:
1. Using Structure Builder
You can create custom list views using the Structure Builder that filter documents based on references. For example:
S.listItem()
.title('Movies with Tom Cruise')
.child(
S.documentList()
.title('Movies with Tom Cruise')
.filter('_type == "movie" && references($actorId)')
.params({ actorId: 'tom-cruise-actor-id' })
)2. Using GROQ Queries
You can use the references() function in GROQ to find documents that reference a specific document:
*[_type == "movie" && references("actor-id-here")] {
title,
cast[]->{ name }
}This finds all movies that reference the specified actor ID anywhere in their structure.
Customizing Search Behavior
According to the Studio search configuration docs, you can also customize how search works in Studio by:
- Defining custom field weights - Make certain fields (like actor names) more important in search results
- Configuring search strategies - Choose between different search implementations (groqLegacy, groq2024, textSearch)
So while the global Studio search doesn't automatically show "reverse references" out of the box, you have powerful tools to set up exactly the kind of reference-based search you need!
Sanity β Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.