Blog

    Concepts and Applications of Elasticsearch: Searching Clinical Documents Without Exposing PHI

    By GauravSeptember 10, 20269 mins read
    On this page

    Concepts and applications of Elasticsearch are easiest to understand through one demanding use: full-text search over clinical documents such as discharge summaries, referral letters and scanned reports. The core concepts, indices, mappings, analyzers and aliases, all matter there, and each one has a consequence for protected health information.

    Startup founders and product and engineering leaders building search into a health app will find how to design the index, enforce access per document, reindex safely and keep logs from leaking what the index protects.

    What are the core concepts and applications of Elasticsearch?

    The core concepts of Elasticsearch are documents stored as JSON, indices that hold them, mappings that define each field, analyzers that prepare text for search, and aliases that point to indices. Its applications include full-text search over clinical documents, where Agnotic Technologies builds indexes that respect per-document access and protect PHI.

    Adding search over clinical notes?

    We design the index, the access rules and the reindex path before any PHI goes in.

    Elasticsearch is a search engine, not the system of record. The clinical documents live in the EHR or a document store, the index holds a searchable copy, and that copy needs the same protection as the original.

    How should the index for clinical documents be designed?

    The index for clinical documents should hold only the fields search needs, with mappings set explicitly, so nothing is indexed by accident.

    • Explicit mappings: set dynamic mapping to strict, so a new field in the source cannot appear in the index unannounced.
    • Text and keyword fields: note text is analyzed for search, while patient and encounter numbers are keyword fields for exact filters.
    • Access fields: every document carries the attributes access rules need, such as facility, department, patient and any sensitivity label.
    • Minimal content: keep what search and result snippets need, and fetch the full document from the source when it is opened.

    Clinical text needs its own analysis. Abbreviations, drug names and negated phrases such as no evidence of behave differently from ordinary prose, so test the analyzer on real, de-identified notes.

    Clinical document search in Elasticsearch: documents flow from the EHR or document store through an ingestion pipeline into an index with access fields, and every user search passes through role-based document and field filters before results return, with an alias switched to a rebuilt index during reindexing

    How do you control access to each document?

    Control access to each document by filtering every search with the user's permissions, enforced by Elasticsearch roles or by a search service that adds the filter, never by the client application.

    Elasticsearch document level security lets a role define a query that limits which documents it can read, and field level security limits which fields it can read. A role without these limits grants access to all documents and fields, and the document queries of a user's several roles are combined with OR.

    The OR rule matters in practice. A user who holds a broad role and a narrow one sees everything the broad role allows, so design roles so the most permissive grant is the intended one.

    • Role per access pattern: clinicians at one facility, or a care team for assigned patients, written as a query on the access fields.
    • Templated queries: insert user attributes such as facility into the role query, rather than creating a role for every user.
    • Sensitive documents: restricted notes carry a label that excludes them unless the user's role allows it.
    • Emergency access: break-glass access goes through a separate, logged path, never by widening a normal role.

    Elastic states that document and field level security is meant to operate with read-only privileged accounts. Document level security does not apply to write APIs, and the update API is not supported for restricted roles.

    So the accounts that write to the index, such as the ingestion pipeline, should be separate service accounts with write privileges, and users should search through accounts that can only read.

    What does the HIPAA Security Rule mean for a search index?

    The HIPAA Security Rule treats a search index like any other system holding ePHI, so access control and audit logging apply to search as they do to the EHR.

    The HIPAA Security Rule access control standard, 45 CFR 164.312(a)(1), requires technical policies and procedures that allow access to electronic protected health information only to persons or software programs granted access rights, and 164.312(b) requires mechanisms that record and examine activity in systems containing ePHI.

    • Log who searched, when and with which filters, and which documents they opened.
    • Keep search terms out of general application logs, since a query can contain a patient's name or diagnosis.
    • Encrypt the cluster's traffic and storage, including snapshots.
    • Restrict snapshot repositories, because a snapshot is a full copy of the index.

    How do you reindex without exposing PHI?

    Reindex without exposing PHI by building the new index under the same protections as the old one, then switching an alias, so users never query an unprotected copy.

    • Step 1, create the new index with its final mappings and settings before any data goes in.
    • Step 2, make sure role restrictions cover the new index name, for example through an index pattern the roles already use.
    • Step 3, fill it with the reindex API or by replaying from the source, using a service account.
    • Step 4, compare document counts and run test searches as users with different roles.
    • Step 5, move the alias from the old index to the new one in a single action.
    • Step 6, delete the old index and any temporary copies, and check snapshots for leftovers.

    Reindexing from the source system is often safer than copying the old index, because it also applies corrections and removals made since the first load.

    Keeping deletions and corrections in step

    Deletions and corrections in the source must reach the index quickly, or search will show documents that should no longer appear.

    • Entered in error: a note marked as wrong in the EHR is removed from the index or hidden, not left searchable.
    • Patient merges: documents move to the surviving patient, and their access fields update with them.
    • Access changes: a document relabeled as sensitive is updated in the index straight away.
    • Reconciliation: a scheduled job compares the index with the source and fixes differences.

    Search relevance for clinical text

    Search relevance for clinical text depends on how notes are written, so tune it with the people who will search.

    • Synonyms and abbreviations: map common clinical shorthand to full terms, reviewed by a clinician.
    • Phrase matching: favor exact phrases for drug names and diagnoses, where loose matching misleads.
    • Negation: a note saying a condition was ruled out should not rank as if it confirms it, so show snippets that make context visible.
    • Recency: newer documents often matter more, so add date as a ranking factor rather than a hard filter.

    Running the cluster safely

    Running the cluster safely means treating it as production infrastructure that holds ePHI, with the same controls as the database behind your app.

    • Private network access only, with no public endpoint for the cluster.
    • Separate clusters or strict index separation for test and production, and no real PHI in test.
    • Version upgrades planned and rehearsed on a copy, since mappings and security settings can behave differently.
    • Snapshots encrypted, restricted and tested by restoring them into a protected environment.

    A worked example: search across a multi-site clinic group

    A worked example: a clinic group runs several sites. Clinicians should search notes only for patients seen at their own site, while a care coordinator searches across sites for assigned patients.

    Each indexed document carries the site and the assigned care team. The clinician role filters on the user's site, inserted from their profile, and the coordinator role filters on care team membership. Notes labeled sensitive carry an extra field that both roles exclude unless the user holds a separate, audited permission.

    When the group opens a new site, the change is a new value in the access field, not a new index or a code change.

    What are the common mistakes with Elasticsearch over clinical documents?

    The common mistakes with Elasticsearch over clinical documents come from treating the index as a cache rather than a second copy of the record.

    • Filtering in the front end: the API returns documents the user should not see, and the browser hides them.
    • Dynamic mapping left on: a new source field full of free text is indexed without review.
    • A broad role left on users: the OR rule gives them more than any narrow role intended.
    • Search terms in logs: patient names end up in log tools with wider access than the index.
    • Forgotten copies: old indices and snapshots remain after a reindex.

    What does clinical document search mean for your build plan?

    Clinical document search needs an ingestion pipeline from the EHR or document store, index design, access rules, a search API, audit logging, reindex procedures and reconciliation. Access design should come before the first document is indexed.

    • List the document types, their sources and which ones are sensitive.
    • Define access patterns with clinical and privacy leads.
    • Decide whether Elasticsearch roles or a search service enforce filters, and test both allowed and denied searches.
    • Plan the reindex and deletion procedures before launch, not after the first mapping change.

    How does Agnotic build search over clinical documents?

    Agnotic builds the ingestion pipeline, the index mappings and analyzers, per-document access rules, the search API, audit logging and the reindex and reconciliation jobs. We design access with your privacy team and test it with searches made as each role before any clinician uses it.

    Clinical search with access built in

    Every query filtered by role, every search logged and every reindex protected.

    Sources

    Frequently Asked Questions

    Use it as a searchable copy, not the system of record. The originals stay in the EHR or document store, and the index holds what search needs.

    Talk to an engineer about your project

    Tell us which documents your users need to search and who may see what. We will design the index and the access rules around that.

    Go deeper

    Services and solutions on this topic