Document-Level Security in Elasticsearch
How Elasticsearch lets two people run the exact same search and see two different, correctly restricted sets of results — explained from the ground up with analogies, diagrams, and real production thinking.
Picture a hospital system running one shared Elasticsearch cluster to power search across patient records for its entire staff. A cardiologist searching for a patient’s name should see that patient’s cardiology history. A billing clerk searching the same name should see billing details, not clinical notes. A nurse on one ward should never see records from a ward they do not work on. All of this data lives in the very same index, searched through the very same API, by people logging in with their own individual accounts.
The Elasticsearch feature that makes this possible — restricting which individual documents a given user is allowed to see, rather than restricting access at the level of a whole index — is called Document-Level Security, usually shortened to DLS. This article walks through DLS piece by piece: what it is, why coarser access controls are not enough, how it actually filters results behind the scenes, how to configure and roll it out safely, and how to avoid the mistakes that turn a well-intentioned security feature into either a data leak or a support headache.
Every new term is explained the first time it appears, with an everyday analogy and a real production example, so no prior Elasticsearch knowledge is assumed. In keeping with how this topic is normally taught at the conceptual level, no code or configuration snippets are shown — the focus stays on what DLS does and how to reason about it safely, rather than on exact syntax.
1What Is Document-Level Security?
Document-Level Security restricts which individual documents inside an index a specific user is allowed to see, rather than granting or denying access to the whole index at once.
Start with the plain-English definition
Elasticsearch stores information as JSON documents inside containers called indices, and controls who can do what through a security model built around users and roles. A role is a named set of permissions, such as which indices can be searched, which can be written to, and which administrative actions are allowed. Ordinarily, a role’s permissions apply to an entire index at once: a user either can search a given index, or cannot.
Document-Level Security adds a finer layer underneath that index-level permission. Instead of a role simply saying “this user can search the patient-records index,” a DLS-enabled role says “this user can search the patient-records index, but only see the documents matching this specific condition,” such as documents belonging to their own department. The condition is expressed as a query, evaluated automatically and invisibly for every single search that role’s users run.
Think of a large shared filing room with one set of cabinets. Index-level security is like deciding who is allowed into the room at all. Document-Level Security is like each cabinet drawer being lined so that a given employee can only see the folders relevant to them, even while standing in front of the exact same drawer as a colleague who sees a different subset of folders inside it.
Why DLS is invisible to the end user
A defining trait of DLS is that it does not require the searching application or the end user to do anything differently. The same search request, sent by two different users with two different roles, simply returns two different result sets, filtered automatically before those results ever leave the cluster. Nobody has to remember to add an extra filter to their query for security to be enforced.
The three jobs DLS is used for
Multi-tenant isolation
Ensuring one customer or department’s data is never visible to another, even though everyone’s data lives in the same shared index.
Role-based visibility
Matching what a user can see to their actual job function, such as a doctor seeing clinical data and a billing clerk seeing financial data.
Regulatory compliance
Meeting legal or contractual obligations that specifically require restricting access to certain records based on attributes such as ownership, region, or classification level.
A few numbers worth remembering
The big picture
Here is the whole story in one diagram. A user authenticates, their roles are resolved, and any DLS query attached to those roles for the target index is silently combined with the user’s own search before it ever touches the actual data.
flowchart LR U["User logs in"] --> R["Roles resolved
e.g. cardiology-staff"] R --> D["DLS query attached to role
e.g. department = cardiology"] U --> Q["User's own search query"] Q --> C["Combined query:
user's search AND DLS restriction"] D --> C C --> M["Matching engine"] M --> Res["Filtered results returned"]
Read the diagram left to right. The user never sees or writes the DLS restriction themselves — it comes entirely from their assigned role. Their own search query is combined with that restriction, and only documents satisfying both ever reach the matching engine at all, let alone the final results.
What DLS does not do
DLS does not hide specific fields within a document a user is otherwise allowed to see — that is a separate, complementary feature called field-level security, covered in Chapter 8. DLS also does not replace index-level access control entirely; a user still needs basic permission to search an index before DLS can even apply a restriction on top of that permission.
2Why Document-Level Security Exists: The Problem It Solves
Index-level access control alone forces an uncomfortable choice between duplicating data across many indices or accepting that everyone with index access sees everything in it.
Four situations where index-level control alone falls short
Shared platforms
A software-as-a-service platform serving many customers from one shared index needs each customer to see only their own data, without provisioning a separate index per customer.
Internal enterprise search
A single company-wide search index spanning many departments needs each employee to see only the records relevant to their own role or team.
Regional data restrictions
Some data must only be visible to staff in a specific region or under a specific legal jurisdiction, even though the underlying data physically lives in one shared cluster.
Personal or team-owned records
A user should see records they personally created or own, and not necessarily every record of that same type created by someone else.
The alternative nobody wants: an index per tenant
Without DLS, the traditional workaround is creating a completely separate index for each tenant, department, or region needing isolated visibility. This works, but it multiplies operational overhead: more indices to manage, more shards consuming cluster resources, more mapping and template consistency to maintain, and a real risk of configuration drift between them over time as the number of separate indices grows into the hundreds or thousands.
Giving every customer their own separate filing cabinet, in an entirely separate room, works fine for a handful of customers. Once there are thousands of customers, maintaining thousands of identical rooms, each needing the same furniture, the same lighting, and the same locks kept in sync, becomes its own enormous burden. A single shared room, with drawers that automatically show each person only their own folder, scales far more gracefully.
A short history of access control in Elasticsearch
Early index-level permissions only
Elasticsearch’s security features originally focused on controlling access at the index level: which roles could read or write to which indices, with no finer granularity available.
Field-level and document-level security introduced
As Elasticsearch’s security features matured, both field-level security and document-level security were introduced together, letting roles restrict not just which indices, but which fields and which documents within them, a user could see.
Wider adoption in multi-tenant platforms
As more organizations built shared, multi-tenant search platforms on Elasticsearch, DLS became a standard tool for isolating tenant data without multiplying the number of physical indices.
Enterprise search platforms serving a whole organization commonly report that document-level security is what makes a single, unified search experience possible at all — without it, teams either accept oversharing across departments or fragment search into many separate, harder-to-maintain systems.
3Core Concepts: Roles, Role Queries, and the Security Model
Three ideas underpin everything else in this guide: what a role actually is, what a role query means, and how a user’s overall access is determined when they may hold several roles at once.
Roles: the basic unit of permission
A role is a named, reusable bundle of permissions: which index patterns can be accessed, what actions are allowed against them, such as reading or writing, and optionally, a DLS restriction and a field-level security restriction layered on top. A user is assigned one or more roles, either directly or through an external identity system mapped into Elasticsearch’s security layer.
Role queries: the mechanism behind DLS
The DLS restriction attached to a role is itself expressed as a role query: an ordinary Elasticsearch query, of the same kind used in a normal search request, but stored as part of the role definition rather than sent by the end user. Because it uses the same query capabilities available everywhere else in Elasticsearch, a role query can range from a simple exact match on a department field to a more elaborate condition combining several fields together.
A role query is like a standing instruction given to a librarian ahead of time: “whenever this particular badge is shown, only bring books from the reference section, never from the restricted archive.” The instruction is set once and applied automatically every time that badge is presented, without the librarian needing to ask or the visitor needing to request it specially.
Combining multiple roles: the union rule
A user frequently holds more than one role at once. When two or more of a user’s roles each grant access to the same index, but with different DLS restrictions, Elasticsearch does not require both restrictions to match at the same time. Instead, it treats the combination as a union: a document is visible if it satisfies at least one of the applicable roles’ restrictions, not only if it satisfies all of them simultaneously.
| Scenario | Resulting visibility |
|---|---|
| User has one role with a DLS restriction for department A | Sees only documents belonging to department A |
| User has two roles, restricted to departments A and B respectively | Sees documents belonging to either department A or department B |
| User has one role with a DLS restriction, and another role for the same index with no restriction at all | Sees every document, since the unrestricted role grants full visibility for that index |
Because of the union rule shown in the last row above, accidentally granting a user any role for an index with no DLS restriction at all completely defeats every other DLS restriction that same user might otherwise have for that same index. This single fact is responsible for a large share of real-world DLS misconfigurations, and is revisited in Chapter 14.
4Anatomy of a DLS Configuration
Without showing configuration syntax directly, this chapter describes the pieces a DLS setup is built from, and how they fit together conceptually.
A DLS configuration resembles a badge-access policy at a large office building: which floors a badge opens at all corresponds to index-level permission, and a note attached to that badge saying “only the east wing on this floor” corresponds to the document-level restriction layered on top.
The building blocks
Index pattern
Which index or indices, identified by name or pattern, this particular permission entry within the role applies to.
Privileges
What actions are allowed against the matched indices, such as reading, and separately whether DLS even applies to write operations, covered in Chapter 7.
The role query
The actual filtering condition, written as a standard query, describing which documents a holder of this role may see within the matched indices.
Templated values
A way for the same role definition to be reused across many different users, with the restriction automatically adapting to each individual user’s own identity or attributes, covered in Chapter 18.
Where roles and users actually connect
A role definition on its own restricts nothing until it is assigned to at least one user. That assignment can happen directly, by explicitly listing a role on a user’s account, or indirectly, through role mapping rules that automatically assign roles based on attributes coming from an external identity provider, such as a department field supplied during single sign-on. Either way, the DLS restriction itself is defined once, on the role, and then applies uniformly to every user who ends up holding that role.
One role, reused across many users
| Design choice | Trade-off |
|---|---|
| One shared role with a templated restriction | Easy to maintain centrally, scales to many users without new roles per person |
| One dedicated role per user or per small group | More explicit and easier to audit individually, but harder to maintain at scale |
For any platform with more than a handful of distinct visibility groups, a small number of templated roles that adapt automatically to each user’s own attributes is far easier to maintain correctly than a large number of near-identical, individually written roles.
5Internal Working: How DLS Filters Enforce at Query Time
Following one search request from arrival to filtered result shows exactly where and how DLS enforcement fits inside the broader query execution pipeline.
Step by step
Authentication
The user’s identity is verified, whether through a username and password, an API key, or a token issued by an external identity provider.
Role resolution
Every role assigned to the authenticated user, whether directly or through mapping rules, is resolved into one combined set of effective permissions for this request.
DLS restriction gathered
For the specific index being searched, any DLS role queries from the user’s applicable roles are collected, ready to be combined following the union rule from Chapter 3.
Restriction combined with the user’s query
The user’s own search request is wrapped so that it only considers documents also satisfying the applicable DLS restriction, transparently to the requester.
Matching happens against the combined condition
The actual document matching runs against this combined condition, meaning a document failing the DLS restriction is never retrieved as a candidate at all, not merely hidden afterward.
Filtered results are returned
Only documents satisfying both the user’s own search terms and the DLS restriction ever appear in the response.
sequenceDiagram participant Client participant Auth as Authentication participant Roles as Role Resolution participant Node as Coordinating Node Client->>Auth: Request with credentials Auth->>Roles: Identity confirmed Roles->>Roles: Resolve roles and DLS queries Roles->>Node: Effective permissions and restrictions Node->>Node: Combine restriction with user's query Node->>Node: Match only documents satisfying both Node-->>Client: Filtered results
Why enforcement happens before matching, not after
A crucial design point is that DLS restrictions are applied as part of the matching process itself, not as an afterthought filtering an already-retrieved result list. This matters for both correctness and performance: pagination, aggregations, and result counts all reflect the restricted view consistently, rather than a raw total that then gets trimmed down inconsistently after the fact.
Because the restriction is baked into the underlying query execution rather than applied as a separate filtering step afterward, aggregations computed alongside a restricted search are also computed only over the documents that user is permitted to see, keeping counts, sums, and other aggregate values consistent with what that user is actually shown.
6Data Flow: From Login to Filtered Results
Zooming out from one request’s internal mechanics to the whole user journey shows how DLS fits alongside authentication and authorization as a complete access control story.
The three stages of the overall flow
Authentication
Confirming who the user actually is, through whatever identity mechanism the deployment uses.
Authorization
Determining what that confirmed identity is allowed to do at all, including basic index-level access and any DLS or field-level restrictions attached to their roles.
Enforcement
Applying those restrictions transparently to every search, update, or other operation the user performs, for as long as their session or credentials remain valid.
flowchart TD A["User authenticates"] --> B["Roles and attributes resolved"] B --> C["Role definitions loaded,
including DLS role queries"] C --> D["User issues a search"] D --> E["DLS restriction silently applied"] E --> F["Filtered results returned"] F --> G["User issues another search later"] G --> E
How this interacts with external identity providers
Many organizations manage user identity through an external system, such as a corporate directory or a single sign-on provider, rather than creating individual user accounts directly inside Elasticsearch. Role mapping rules translate attributes coming from that external system, such as a department or group membership claim, into the appropriate Elasticsearch roles at login time, which is what then determines which DLS role queries apply for that session going forward.
DLS applies consistently across the whole session
If a user’s role or department changes, but they are using a long-lived, already-issued credential such as an API key created under the old role, that credential continues to enforce whatever restrictions were in effect when it was created, until it expires or is explicitly revoked. Rotating or invalidating credentials after a role change is necessary for the new restriction to actually take effect, a point revisited in Chapter 10.
7DLS in Depth: Query Types and Role Combination Rules
Chapter 3 introduced the role query as the mechanism behind DLS. This chapter looks more closely at what kinds of restrictions are practical, and exactly how they behave when several apply at once.
Common shapes of a role query
Exact-match restriction
The simplest and most common form: a document is visible only if a specific field, such as a department or tenant identifier, equals a specific value tied to the user’s own identity or role.
Range-based restriction
Visibility limited to documents whose value in a field, such as a classification level or a date, falls within an allowed range for that role.
Templated, identity-aware restriction
A restriction whose value is not fixed in the role itself, but filled in dynamically from the logged-in user’s own attributes at query time, letting one shared role serve many different users correctly, as introduced in Chapter 4 and expanded in Chapter 18.
Compound restriction
Several conditions combined together, such as requiring both a matching department and a matching data classification, for cases where a single simple condition is not precise enough.
DLS applies to reads; writes need separate handling
By default, DLS restrictions govern what a user can see when searching or retrieving documents. They do not automatically prevent a user from writing a document that falls outside their own restriction, unless separate write-time validation, such as an ingest pipeline check or application-level enforcement, is also put in place. This distinction matters enough that Chapter 11 covers it as a specific security consideration in its own right.
How restrictions from several roles truly combine
Expanding on the union rule introduced in Chapter 3: when a user holds multiple roles, each granting access to the same index with its own DLS query, Elasticsearch effectively evaluates “does this document satisfy role A’s restriction, or role B’s restriction, or any other applicable role’s restriction,” and shows the document if any single one of them is satisfied. This is a logical or, not a logical and, across roles.
| Role combination | Effective visibility |
|---|---|
| Role A: department = sales; Role B: department = marketing | Documents from either sales or marketing |
| Role A: department = sales; Role B: no restriction for the same index | All documents, since the unrestricted role wins |
| Only Role A: department = sales | Only documents from sales |
Because combining roles always widens visibility rather than narrowing it, role design should treat each role as granting a specific slice of access, with the full picture of what a user can see being the deliberate sum of every role they hold, rather than assuming roles will somehow intersect to narrow things down.
8Interplay with Field-Level Security and Mappings
DLS is often deployed alongside a closely related feature, field-level security, and understanding how the two combine avoids a common source of confusion.
Two different questions, two different features
Which documents?
Document-level security controls whether an entire document is visible to a user at all, based on the role query described in earlier chapters.
Which fields?
Field-level security controls which specific fields within a document a user is allowed to see, hiding sensitive fields such as a salary or a medical diagnosis even from users who can see the rest of that same document.
The two features are independent and commonly used together on the same role: a role might restrict a billing clerk to only documents belonging to their own assigned accounts through DLS, while separately hiding clinical notes fields on those same documents through field-level security, since a billing clerk may need visibility into an account’s existence without needing its full medical detail.
If DLS decides which folders a person is handed at all, field-level security decides which pages inside an allowed folder have certain paragraphs blacked out. Both apply to the same folder, but they answer different questions, and a folder can be fully visible under DLS while still having specific sections redacted under field-level security.
Caching considerations specific to DLS
Elasticsearch’s query and request caches are aware of security context, so cached results for one role’s restricted view are not served to a user under a different role that would see a different set of documents. This keeps caching safe, but it does mean that a cluster serving many distinct roles against the same index benefits less from a single shared cache than a cluster where everyone sees identical, unrestricted results, since the cache effectively has to maintain separate entries per distinct restriction.
What an interviewer may ask
10High Availability and Reliability
Because DLS is part of the security layer rather than a separate service, its availability story is tightly coupled to the cluster’s own normal resilience, with a few DLS-specific details worth knowing.
Role and DLS definitions are cluster metadata
Role definitions, including any attached DLS role queries, are stored as part of the cluster’s own security configuration, which is replicated and persisted the same way other critical cluster metadata is. A node restart, a master election, or a shard relocation does not affect which DLS restrictions apply, since every node involved in serving a request consults the same consistently replicated role definitions.
What can actually go wrong operationally
Stale cached credentials after a role change
As introduced in Chapter 6, an already-issued long-lived credential continues enforcing the restriction that was in effect when it was created, until it is refreshed, rotated, or expires.
Role mapping misfires during identity provider outages
If an external identity provider supplying attributes used for role mapping becomes unreachable or returns incomplete data, a user might fail to receive the expected role, or the deployment’s fallback behavior might grant broader or narrower access than intended.
flowchart TD
A["User's department changes"] --> B["Role mapping updated centrally"]
B --> C{"User has an active long-lived credential?"}
C -->|"Yes"| D["Old credential still enforces old restriction until rotated"]
C -->|"No"| E["Next login picks up new role and restriction immediately"]
D --> F["Rotate or revoke old credential"]
F --> E
Reliability comes from treating role changes as real deployments
Modifying a role’s DLS query changes what an entire population of users can see, potentially immediately for new sessions and eventually for all sessions as credentials refresh. Treating this with the same care, testing, and rollback readiness as any other production configuration change avoids an accidental, wide-reaching visibility mistake.
11Security Considerations
DLS is itself a security feature, so this chapter looks specifically at how it can be undermined, misconfigured, or bypassed if not set up with care.
The union-rule risk, revisited
As covered in Chapters 3 and 7, granting a user any role that has unrestricted access to an index completely overrides every other DLS restriction that user might otherwise have for that same index, because roles combine as a union. A single overly broad administrative or “just in case” role, granted alongside otherwise carefully restricted roles, is the most frequent real cause of an unintended DLS bypass.
Writes are generally not restricted by DLS alone
As noted in Chapter 7, DLS by default governs visibility on read operations, not write operations. A role permitting a user to write to an index does not automatically prevent them from writing a document that falls outside their own DLS restriction, unless separate validation is layered in, such as an ingest pipeline enforcing that a written document’s ownership field matches the writer’s own identity. Treating DLS as a complete write-time access control on its own is a mistake worth avoiding.
Superuser and administrative access bypasses DLS by design
Certain built-in administrative privileges are intentionally allowed to bypass DLS restrictions entirely, since cluster operators and certain administrative tools genuinely need full visibility to do their jobs, such as reindexing or diagnosing cluster health. This is by design, not a flaw, but it does mean that the set of accounts and service credentials holding such elevated privileges deserves the same tight control and auditing as any other powerful administrative capability.
Role queries themselves can be a subtle information channel
Inference through absence
In rare, highly sensitive scenarios, the fact that a search returns zero results, compared to returning some results, can itself leak a small amount of information about what exists outside a user’s restricted view, worth considering for extremely sensitive datasets.
Aggregation-based inference
Even with DLS correctly restricting individual documents, a permitted aggregation could in unusual cases reveal indirect statistical information about the broader, restricted dataset, which is worth reviewing specifically for particularly sensitive use cases.
Because a role’s effective visibility depends on every other role a given user might also hold, a periodic review of role assignments and their combined effect, not just a one-time review at the moment a role was first created, catches drift such as an overly broad role being added later for an unrelated reason.
12Monitoring, Logging, and Metrics
Because DLS enforcement is invisible by design, visibility into whether it is working correctly has to come from deliberate logging and monitoring, not from casual observation.
What to watch
Security audit logging
Elasticsearch’s audit logging can record authentication events and access decisions, providing a trail useful for confirming which roles were actually applied to a given request.
Configuration change tracking
Tracking when a role, especially one with a DLS restriction, is created, modified, or deleted, gives a clear record of exactly when a visibility change took effect.
Unexpected result volumes
A sudden, unexplained increase in the volume of results a particular role or user is retrieving can be an early signal of a DLS misconfiguration granting broader access than intended.
DLS-relevant field health
Monitoring for missing or malformed values in fields that role queries depend on, following the data-quality concern raised in Chapter 8, catches a subtle security gap before it becomes an incident.
A practical DLS verification habit
Whenever a DLS-related role is created or changed, logging in as a representative test user under that exact role, and confirming both that expected documents are visible and that specific known-restricted documents are not, catches misconfigurations immediately. This mirrors the same before-and-after verification discipline recommended for other sensitive configuration changes throughout Elasticsearch operations.
flowchart LR
A["Role created or changed"] --> B["Log in as representative test user"]
B --> C["Run known test searches"]
C --> D{"Expected documents visible,
restricted documents hidden?"}
D -->|"Yes"| E["Deploy with confidence"]
D -->|"No"| F["Investigate role query and role combination"]
A periodically refreshed summary document listing each DLS-relevant role and, in plain language, what it restricts, gives both engineers and compliance stakeholders a fast way to answer “who can see this kind of data” without having to reverse-engineer the answer from raw role definitions each time.
13Deployment and Cloud Context
DLS behaves consistently across self-managed, Elastic Cloud, and Kubernetes-based deployments, since it is a security-layer feature rather than an infrastructure-specific one.
Full configuration control
Operators define roles, role mappings, and DLS restrictions directly, and are fully responsible for integrating with whatever identity provider the organization uses.
Same security features
DLS works the same way on Elastic Cloud as self-managed, configured through the same role and security APIs, though identity provider integration is set up through the cloud console’s own workflow.
Declarative role management
Roles and role mappings can be defined as Kubernetes custom resources, keeping DLS configuration in version control alongside the rest of a deployment’s definition.
Roles as infrastructure-as-code
Because a DLS misconfiguration can have serious consequences, most mature deployments manage role definitions, including their DLS restrictions, the same way they manage any other sensitive infrastructure configuration: stored in version control, applied through an automated and reviewed deployment pipeline, and never edited ad hoc directly against a live cluster without that same review.
Organizations already running an identity governance process for other systems generally extend that same process to cover Elasticsearch role mappings, rather than treating Elasticsearch’s access control as a separate, disconnected system to govern independently.
14Design Patterns and Anti-Patterns
Years of production DLS usage have surfaced patterns worth copying, and an equally memorable set of habits worth avoiding.
Patterns worth copying
Templated roles for large user populations
A small number of shared, identity-aware role templates, introduced in Chapter 4 and expanded in Chapter 18, scale far better than a unique role written per individual user.
Least-privilege role assignment
Assigning users only the roles their actual job function requires, and avoiding “just in case” broader roles, directly protects against the union-rule bypass risk described in Chapter 11.
Dedicated, monitored DLS-relevant fields
Treating any field a role query depends on as a first-class, carefully validated piece of data, following the guidance in Chapter 8, rather than an incidental field that happens to be reused for security.
Routine verification testing
Logging in as a representative test user after every DLS-related change, following the practice described in Chapter 12, catches misconfigurations before real users ever encounter them.
Anti-patterns to avoid
The problem
Granting a broad, unrestricted role alongside carefully scoped DLS-restricted roles, for convenience or as a fallback.
Why it fails
As explained in Chapters 3 and 11, the unrestricted role silently overrides every other restriction for that index due to the union rule, defeating the purpose of the more careful roles entirely.
The problem
Relying on DLS alone to prevent users from writing data outside their intended scope.
Why it fails
As covered in Chapter 11, DLS by default governs read visibility, not write behavior, so a role permitting writes needs separate validation to enforce ownership at write time.
The problem
Letting a DLS-relevant field be populated by unreliable or inconsistent application logic.
Why it fails
A field driving a security restriction that is sometimes missing or wrong translates data-quality issues directly into visibility mistakes, as discussed in Chapter 8.
15Best Practices and Common Mistakes
A concise, practical checklist distilled from the chapters above, organized as habits to lean into and habits to actively avoid.
Do
- Assign roles following least-privilege, avoiding unnecessary broad access
- Use templated, identity-aware roles for large or growing user populations
- Treat any DLS-relevant field with the same rigor as a security control
- Test every DLS-related role change as a representative test user before rollout
- Rotate or revoke long-lived credentials promptly after a role change
- Pair DLS with write-time validation when ownership enforcement matters
Avoid
- Granting an unrestricted “just in case” role alongside carefully scoped ones
- Assuming DLS alone controls what a user can write, not just what they can read
- Leaving a DLS-relevant field to inconsistent or unreliable population logic
- Editing role definitions directly against production without review
- Forgetting that existing long-lived credentials do not immediately reflect a role change
- Treating a one-time role review as sufficient without periodic reassessment
16Trade-offs: Isolation, Complexity, and Operational Overhead
Every DLS decision trades one good thing for another. Naming the trade-off explicitly leads to better decisions than treating any single approach as automatically correct.
| Choice | What you gain | What you give up |
|---|---|---|
| Shared index with DLS | Simpler cluster topology, less operational overhead than many indices | Slightly more per-request evaluation cost, and roles must be designed carefully |
| Separate index per tenant | Physical isolation, simpler mental model per tenant | Far higher operational overhead as tenant count grows, as discussed in Chapter 2 |
| Templated, identity-aware roles | Scales cleanly to large user populations | Slightly more complex to reason about than one role per user |
| DLS combined with field-level security | Fine-grained control over both documents and fields | More configuration surface to review and keep correct over time |
| Pairing DLS with write-time validation | Consistent enforcement across both reads and writes | Additional logic to build and maintain outside DLS itself |
There is no universally correct choice in this table — only the choice that fits how many distinct visibility groups exist, how sensitive the data actually is, and how much ongoing operational discipline a given team can realistically sustain around reviewing and testing roles.
17Real-World and Industry Usage Patterns
DLS’s design choices make far more sense once seen against how organizations actually use it to solve concrete access-control problems at scale.
Healthcare platforms
Systems similar to the hospital example opening this article commonly use DLS to ensure clinical staff see records relevant to their own department or assigned patients, while administrative staff see billing-relevant fields and records without full clinical detail, often combined with field-level security for especially sensitive fields.
Software-as-a-service search platforms
Multi-tenant platforms serving many customers from a shared index commonly use a templated, identity-aware DLS role, described in Chapter 18, so that each customer’s search automatically and invisibly restricts to their own tenant’s data alone.
Enterprise internal search
Company-wide search spanning many departments and document types commonly uses DLS to ensure an employee searching company knowledge only sees documents their own department or clearance level permits, avoiding the need to fragment search across many separate internal systems.
Government and regulated data platforms
Organizations subject to strict regional or classification-based data handling rules commonly use DLS to enforce that staff only see records appropriate to their region or clearance level, treating the role query as a directly auditable expression of a compliance requirement.
Across every one of these patterns, the common thread is the same: DLS lets an organization keep the operational simplicity of one shared, well-maintained index, while still meeting access requirements that would otherwise force fragmenting data across many separate, harder-to-maintain systems.
18Advanced Topics: Templated Queries and Nested Data
Beyond the fundamentals, a couple of advanced mechanisms make DLS considerably more practical to operate at scale, particularly for large or structurally complex datasets.
Templated role queries: one role, many users
Rather than writing a separate role for every individual user or tenant, a role query can be written to automatically substitute values from the currently authenticated user’s own identity or attributes at the moment a search runs. This is what allows a single shared role, such as “tenant-scoped access,” to correctly restrict a thousand different tenant users to a thousand different, individually correct subsets of data, without maintaining a thousand separate role definitions.
This is similar to a single standing instruction that says “only show this visitor documents whose owner field matches their own badge number,” rather than writing out a thousand separate instructions, one naming each specific visitor’s badge number directly. The single instruction automatically adapts correctly to whoever presents themselves.