Full-text search in HAPI FHIR with Lucene or Elasticsearch

Full-text search in HAPI FHIR adds _content and _text search on top of the relational database. This page explains the Lucene and Elasticsearch options, their trade-offs and the setup checks before you go live.

On this page

Full-text search in HAPI FHIR: what it adds and when you need it

Standard FHIR search parameters need no full-text indexer, but _content and _text do. Those two parameters search the narrative and the full content of stored resources, and a HAPI FHIR JPA server can only answer them when a full-text indexer runs alongside the relational database. HAPI FHIR supports two options, an embedded Lucene index and Elasticsearch, and the indexer augments the database rather than replacing it. Resources are still stored, versioned and validated in the database, and the index is a second copy used only to find matching resource IDs before the server returns the results.

The practical question is whether your clients need free-text discovery at all. Ordinary parameters such as identifier, name, code, date and reference cover most clinical lookups and do not require any extra component. Teams usually need _content or _text when a user or application must find a document or narrative by words that appear anywhere in it, such as a clinician searching notes, a records team locating scanned report text, or an application that queries narrative sections. Before you commit, list the actual queries your applications send, mark the ones that depend on free text, and confirm with your application owners whether those searches are essential or a convenience.

Once you decide to enable the indexer, plan for an index that must stay in step with the database. Confirm how your chosen version handles reindexing after a schema or configuration change, how long a full rebuild takes on your data volume, and who runs it. Tokenization and exact-match behavior also differ from what clients may expect from a relational LIKE query, so test representative terms, phrases and identifiers against the index before go-live. Embedded Lucene, enabled by default in the JPA server starter, is the simpler choice for a single instance with modest data. Moving to Elasticsearch adds a separate cluster to operate, and its node roles, a three-node minimum for high availability in the Elasticsearch node roles documentation, and licensing choices become your responsibility. Confirm the security features you need, such as single sign-on and field-level security, against your Elastic subscription tier before you design around them.

Lucene or Elasticsearch: which configuration fits which situation

This table compares the embedded Lucene indexer that the JPA server starter uses by default with an external Elasticsearch cluster across operational footprint, licensing, security and multi-instance fit. Read each row against your own topology and compliance requirements, and treat any cell marked for confirmation as a question to settle with your team before choosing.

ConsiderationEmbedded Lucene (starter default)Elasticsearch (external cluster)
ConfigurationDefault in the starter, set in application.yamlSwitched on in application.yaml and pointed at a cluster you run
Operational footprintRuns inside the HAPI FHIR server with no separate service to operateAdds a cluster to deploy, patch, back up and monitor
Cluster needsNone beyond the JPA server and its databaseHighly available clusters need at least three master-eligible nodes
Multi-instance fitConfirm how each server instance maintains its own index before scaling outShared index that all server instances can query, subject to confirming your setup
Security featuresAccess control depends on the JPA server and the surrounding platformFree Basic tier includes TLS and role-based access control; SSO and field-level security are in paid tiers
LicensingFollows HAPI FHIR's Apache Software License 2.0Default distribution uses Elastic License 2.0; AGPLv3 option exists from 8.16
Support lifecycleTied to your HAPI FHIR version and upgrade planConfirm the end-of-maintenance date for your Elastic release line before choosing
Move triggerConsider moving when index size, query load or instance count outgrows the embedded setupAlready in place once the cluster is running and governed

How tokenization and exact-match behavior affect search results

Full-text indexing does not compare strings character by character. When a resource is indexed, the text is split into tokens, usually words, and those tokens are normalized, for example by changing case or removing some punctuation. A search for _content then matches tokens, not the stored string. The relational database still holds the original resource and still answers exact-value parameters such as identifiers and codes, so the two paths can return different sets for what looks like the same question. A query that finds a narrative phrase in Lucene may miss it in the database, and the reverse can also happen. Teams should expect this difference and design tests around it rather than assume the index is a faster copy of the database.

  • Token splitting: Punctuation, hyphens and slashes can split one term into several tokens, which can widen or narrow matches.
  • Case folding: Matching is usually case-insensitive in the index, but the database comparison may not behave the same way.
  • Stop words and stemming: Common words may be dropped and word endings may be reduced, so a phrase may match a variant spelling.
  • Phrase handling: Multi-word queries may match tokens anywhere in the text unless phrase logic is requested.
  • Dependence on analyzers: The exact rules come from the analyzer configured for each indexer and resource field.

Confirm the analyzer rules for your HAPI FHIR version in the HAPI FHIR Lucene and Elasticsearch docs before writing expected results.

Setting up _content and _text search on a HAPI FHIR JPA server

This sequence takes a HAPI FHIR JPA server from a stock install to a state where _content and _text searches run against a populated full-text index, with each step confirmed before the next begins.

  1. Confirm the JDK and HAPI FHIR version

    The platform engineering lead confirms the Java runtime and the HAPI FHIR version the server will run before any configuration changes. HAPI FHIR 8.2.0 requires JDK 17, so the team checks the release notes for the version it is deploying and confirms the JDK in the build image and the runtime match. Confirm the target version against the HAPI FHIR versions page and the release list rather than relying on an older internal runbook. This step is done when the team has a written version record for the server and a JDK check that passes on the target host or container image.

  2. Choose the full-text indexer

    The architect and the server owner decide between the embedded Lucene indexes that the JPA server starter uses by default and an external Elasticsearch cluster. Lucene needs no separate service, which suits a single instance or a small, low-volume server. Elasticsearch adds a cluster to run, secure and back up, but it moves index load off the application node. Confirm the decision against the expected data volume, the number of server instances and whether the organization already operates Elasticsearch or OpenSearch. Record the choice and the reason in the design document. This step is done when the indexer is named, the owner has signed off, and the team knows which infrastructure it must provision.

  3. Change the indexing configuration in application.yaml

    The engineer edits the application.yaml file used by the JPA server starter to keep Lucene or switch to Elasticsearch, with the connection settings, credentials and index names for the chosen indexer. Keep credentials in the secrets mechanism of the deployment platform rather than in the file itself. Make the change in version control so the diff is reviewable. Confirm the exact configuration keys against the starter README and the HAPI FHIR Lucene and Elasticsearch documentation for the version in use, because key names change between releases. This step is done when the configuration is merged, the server starts without configuration errors, and the startup log shows the selected indexer initialized.

  4. Deploy the server to a non-production environment

    The platform team deploys the configured server to a staging environment that uses the same database engine, JDK and indexer as production. Starting the server with the new configuration creates or updates the index structures in the environment. Check the startup logs and the health endpoints for errors related to the index, the database connection or the Elasticsearch cluster. For Elasticsearch, confirm the cluster is reachable and that the nodes meet the role layout the team has designed, including at least three master-eligible nodes for a highly available cluster. This step is done when the server runs healthy in staging and the index service reports no initialization errors.

  5. Reindex existing resources

    Resources stored before full-text indexing was enabled have no index entries, so the server must reindex them before _content and _text searches return complete results. The operator runs the reindex operation documented for the HAPI FHIR version in use and lets it complete on the staging data set. Monitor progress through the server logs and watch the search-related index size grow. Note that reindexing consumes database and indexer resources and can take a long time on large stores, so the team should schedule it outside peak use and confirm the procedure for their version. This step is done when the reindex job reports completion and a count of indexed resources matches the expected number of text-bearing resources in the data set.

  6. Verify _content and _text queries

    The QA engineer runs a fixed set of _content and _text queries against staging using known test resources with distinctive words, phrases and narrative text. For each query, compare the returned bundle with the resources the test data should match, and include negative cases that should return nothing. Check that the Bundle total and entries match expectations and that stemming, case handling and exact phrase behavior match what the team documented during the design step. Store the queries and expected results in version control so they can be rerun after upgrades. This step is done when every test query returns its documented result set and the test script passes.

  7. Confirm the index stays current after writes

    The engineer creates, updates and deletes a test resource in staging, then runs _content and _text queries that should reflect each change. This confirms that the indexer is updated on write, not only on the initial reindex. Include an update that removes a word, because a search for the old term should stop returning the resource. Record the results and review any lag or missing change with the vendor documentation for the indexer in use. This step is done when write, update and delete changes appear in search results as expected, and the team has written approval to move the configuration toward production.

  8. Deploy to production and repeat the checks

    The platform team applies the same configuration, image versions and reindex procedure to production through its normal change process. After the reindex completes, the QA engineer reruns the stored _content and _text test queries against production with a controlled set of test resources, or with a read-only subset of queries if the data is sensitive. Record the outcome and the index state in the change record. The step is complete when production queries match the staging results and the monitoring for the server and the indexer shows normal behavior.

When to move from embedded Lucene to Elasticsearch

Move from embedded Lucene to Elasticsearch when the server's full-text index has to be shared, watched or operated as a service in its own right. The first trigger is multiple HAPI FHIR server instances that must return consistent _content and _text results. Each embedded Lucene index lives with the JPA server instance that uses it, so a deployment running several replicas behind a load balancer needs a plan for keeping those indexes in step. The second trigger is operational visibility: if your operations team needs to inspect index size, query latency and indexing health with tooling they already use, a separate Elasticsearch cluster gives them that surface. The third is skills. If your organization already runs Elasticsearch for other workloads, the marginal cost of one more index is much lower than the cost of learning a new index lifecycle from scratch.

The cost of Elasticsearch is mostly recurring and mostly operational. You pay for the cluster itself, the storage and memory it needs, the people who patch, back up and upgrade it, and the monitoring that watches it. For high availability, Elastic's node roles documentation says a highly available cluster needs at least three master-eligible nodes, so a production design is larger than a single container beside the HAPI FHIR server. Ask your team to confirm the node count, data tier layout and backup target before comparing this option with embedded Lucene. Also check the Elastic release line you plan to use against the Elastic product end of life dates, since an index that outlives its version's maintenance window creates its own upgrade project.

Migration effort depends on reindexing and testing, not on the configuration change itself. Switching the indexer in application.yaml is short, but the existing indexed data must be rebuilt in the new cluster, and the results of _content and _text queries must be compared against the Lucene baseline for your own data, including tokenization and exact-match behavior. Plan a rehearsal on a copy of production data, measure how long the reindex takes at your data volume, and define acceptance tests for the queries clinicians and integrations actually run. Confirm the licensing and security features you need before you commit, because the Elasticsearch security features available depend on the subscription tier in use.

Security and operational considerations for the search index

A full-text index copies content into a second store with its own access path, so it must be secured, backed up and retested as carefully as the database it mirrors. The cards below cover the authorization gap, the Elasticsearch security and licensing choices, network and access controls, and the operational routines that keep the index in step with the data.

Authorization must apply to index results

A _content or _text query searches the indexed text of resources, so it can return matches from content that a search parameter was meant to hide. Permission checks that narrow ordinary searches do not automatically cover full-text hits. Test with a user who lacks access to specific resources and confirm that the matching resource never appears in the Bundle, the count or the paging links. Review the AuthorizationInterceptor and search narrowing configuration with this path in mind, because HAPI FHIR provides building blocks rather than one security layer.

HAPI FHIR security docs

Choose the Elasticsearch license tier

Elasticsearch and Kibana are available under the Elastic License 2.0, SSPL 1.0 and AGPLv3, and only AGPLv3 is OSI-approved. Confirm which license your organization accepts before the index is deployed, and check whether the distribution you pull matches it. Record the decision in the architecture file, since it affects redistribution and internal policy reviews.

Elastic licensing FAQ

Security features by subscription tier

TLS, the file and native user realms and role-based access control were free in the Basic tier from Elasticsearch 6.8.0 and 7.1.0. Single sign-on, field- and document-level security, and encryption at rest support sit in paid tiers, so confirm which features your deployment needs before relying on them. Platinum is no longer offered to new customers, so ask for current tier terms in writing when you plan a quote.

Elastic subscriptions

Network encryption and index access

Use TLS between the HAPI FHIR server and the Elasticsearch nodes, and restrict the index to a dedicated service account with only the privileges the indexer needs. Keep the cluster off public networks and limit administrative APIs to operators. Verify that the JPA server's credentials cannot read indices belonging to other applications, and that Kibana access is governed separately from FHIR access.

Backups and reindexing plans

The relational database remains the source of truth, so the index can be rebuilt, but a rebuild on a large dataset takes time and load. Document the reindex procedure, who can start it and how users are protected while search results are incomplete. Back up index snapshots as well, and check that restored snapshots keep the same access rules as the live cluster, since a restored index may otherwise expose content.

Retest the index after every upgrade

Upgrades to HAPI FHIR, its Lucene or Elasticsearch client, or the Elasticsearch cluster can change tokenization, index mappings or search results. Repeat exact-match and _text test queries against a fixed dataset, along with the authorization tests above, before promoting the upgrade. Track each Elasticsearch release line against Elastic's end-of-life dates, since unsupported versions stop receiving fixes.

9.x maintenance ends
15 Oct 2027
Elastic end of life dates

Questions teams ask before adding full-text search to HAPI FHIR

What drives the effort for full-text search setup and testing?

Effort depends mainly on how many search parameters and resource types need _content or _text coverage, which indexer you choose, and how much of the existing search behavior must be verified. A Lucene setup inside the starter needs configuration, reindexing and a test pass over the queries clinicians and applications actually run. Moving to Elasticsearch adds a cluster to build, secure and monitor, plus connection settings in application.yaml and a comparison of results against the relational baseline. Ask any partner to break the quote into indexer setup, query testing, reindex planning and cluster work, so each driver is visible.

Can our team add full-text search to HAPI FHIR without outside help?

Yes, a team with Java, Spring Boot and FHIR experience can enable the embedded Lucene indexes that the JPA server starter already uses, because the switch is a configuration change. The harder part is proving the results are right: tokenization, exact-match behavior and ranking differ from plain database search, and those differences affect clinical queries. Teams that keep the work in-house usually need someone who can own the Elasticsearch cluster, its upgrades and its security settings after go-live. Outside help is most useful for the test plan and the cluster build, not for the switch itself.

What do we need to provide before the work starts?

Expect to supply four things: representative test data (ideally de-identified or synthetic), an inventory of the searches your applications run today, access to the target environment or cloud account, and named owners for sign-off. The query inventory matters most, because it defines which _content and _text behaviors must be checked and which existing searches must keep returning the same results. Infrastructure access determines whether the Lucene index lives on the server's storage or whether an Elasticsearch cluster must be provisioned in your network. Confirm data handling rules for test data before any copy leaves production.

How long does full-text search work take?

Duration depends on scope, and no fixed figure applies across deployments. A single-node Lucene setup with a small query inventory is a much smaller job than a multi-node Elasticsearch deployment that must be sized, secured, monitored and tested against production-like volumes. Reindexing time grows with the number of stored resources, so ask for a reindex estimate based on your own data size. Fixed-scope engagements have scope, deliverables and timelines agreed in writing before work starts, so request the timeline as part of that written scope.

Should we move from embedded Lucene to Elasticsearch?

Move when the embedded index no longer meets your operational needs, such as needing an index that can be scaled, monitored and secured separately from the FHIR server, or when your organization already runs Elasticsearch. Keep Lucene when search volume is modest and a single server with a simple index is enough. Either way, the full-text index augments the relational database rather than replacing it, so the database still holds the source of truth. Confirm your indexer choice against the current HAPI FHIR documentation before committing.

What licensing questions come with Elasticsearch?

Elasticsearch and Kibana source code is available under three licenses: Elastic License 2.0 (the default distribution), SSPL 1.0 and AGPLv3. Elastic added AGPLv3 in September 2024 before the 8.16 release to offer an OSI-approved open source option, according to Elastic's licensing FAQ. The Elastic License 2.0 and SSPL are not OSI-approved open source licenses. Security features also vary by subscription tier: Elastic's self-managed subscriptions page says single sign-on, field- and document-level security and FIPS 140-3 mode are among the security features listed, and some tiers differ. Have your legal and procurement teams confirm which license and tier fit your policy before you choose a distribution. OpenSearch is a fork of Elasticsearch 7.10, so compatibility with HAPI FHIR's Elasticsearch support must be checked separately.

What recurring work follows go-live?

The recurring work depends on the indexer. With embedded Lucene, plan for index rebuilds after upgrades or schema changes, backups that include index data, and checks after each HAPI FHIR release. With Elasticsearch, add cluster operations: version upgrades (Elastic 9.5.5 and 9.4.8 were released on October 6, 2026, with 8.19.23 still maintained), end-of-life planning for your current line (Elastic lists end of maintenance for 8.x on January 15, 2027), node capacity, and patching. A highly available cluster needs at least three master-eligible nodes, which affects the recurring footprint. Retainers for upgrades, support and continuous testing are available from DeployOpen when you want this work handled after go-live.

How DeployOpen scopes and delivers full-text search for HAPI FHIR

DeployOpen scopes full-text search in writing before any configuration starts. The first step is a query inventory: the list of _content and _text searches your clinical, operational and reporting users actually run, with the resource types they touch, the expected result volumes and the response times they need. That inventory decides whether the work is a small embedded Lucene setup or a separate Elasticsearch cluster, and it drives the indexer choice, which is documented in each option's own terms by the team that owns the server. The written scope then names the HAPI FHIR version, the JDK, the database (PostgreSQL or Microsoft SQL Server for production), the starter deployment method and the indexer, so the boundaries are agreed before anyone touches application.yaml.

Configuration runs in your infrastructure, under your accounts and change process. For Elasticsearch, the scope covers node roles, a highly available cluster that needs at least three master-eligible nodes, the TLS and user settings, index lifecycle and backup, and the choice between Elastic's self-managed tiers, Elastic Cloud on Kubernetes or a platform you already operate. Your licensing review belongs in that scope, because the default Elastic distribution is under the Elastic License 2.0 and the subscription features you need for single sign-on or field-level security sit in paid tiers. DeployOpen's verification tests then check that _content and _text return the expected hits, that exact-match and tokenization behavior matches your query inventory, that reindexing and failover work, and that the indexes stay consistent with the relational database. Handover covers runbooks, dashboards and the configuration record.

DeployOpen does not publish a price list. A quote follows from the written scope, and the main cost drivers are the size of the query inventory, the number of resource types and the indexer decision. Ask for the setup and handover as a one-time fixed scope, and ask separately for any recurring work such as upgrades, reindexing support or continuous testing, which is available as a retainer. Confirm with your own team who will operate the search cluster after handover, because that person's skills decide how much support you need later.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.