Prompt
What should I use for permissions-aware search?
Latest observation
For permissions-aware search, the best choice is usually Elasticsearch or OpenSearch, with permissions enforced at query time.
Common approaches
1. Search engine + ACL filtering
Use a search engine and store document permissions as fields, then filter every query by the user’s allowed principals.
- Example fields:
allowed_user_ids,allowed_group_ids,tenant_id - Query pattern: search text AND permission filter
- Good for:
- full-text search
- faceting
- ranking
- large result sets
- Caveat: ACL filters can get expensive if permissions are very granular
2. Precomputed visibility / denormalized access control
If permissions are complex, precompute a visibility field or “who can see this” list at indexing time.
- Good when permissions change relatively infrequently
- Makes queries simpler and faster
- Needs reindexing or document updates when permissions change
3. Separate indexes / partitions by tenant or security domain
If access is mostly separated by tenant or team, shard the corpus by tenant and search only within that index.
- Simple and efficient
- Best when isolation boundaries are clear
- Not ideal for highly dynamic cross-tenant permissions
4. Database-backed search with row-level security
If your search needs are modest, a relational DB with full-text search plus row-level security can be enough.
- PostgreSQL full-text search + RLS is a strong option
- Simpler architecture
- Usually less powerful than a dedicated search engine for relevance and scale
Recommendation
- Large-scale / rich search: Elasticsearch or OpenSearch
- Simple app / moderate scale: PostgreSQL full-text search + row-level security
- Strict enterprise security requirements: use a search engine, but apply authorization in the application or an authorization layer, not just in the UI
Important caution
Do not rely on client-side filtering or post-processing search results alone. Permissions must be enforced before results are returned.
If you want, I can suggest the best option based on your stack, scale, and permission model.