-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add Elasticsearch index prefix configuration #891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…source filtering in pom.xml
…factor hibernate properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive Elasticsearch configuration capabilities to the HAPI FHIR JPA server, focusing on index prefix configuration, custom client setup, and security updates. The changes enable users to configure custom prefixes for Elasticsearch indices and update dependencies for security fixes.
Key Changes:
- Index prefix configuration for Elasticsearch indices via
hapi.fhir.elasticsearch.index_prefix - Custom Elasticsearch client bean configuration that bypasses the default Spring Boot sniffer
- Logback dependency updates to version 1.5.19 to address CVE-2025-11226
- Hibernate property configuration refactoring from nested to flat format
- Resource filtering enabled with Maven for property placeholder substitution
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/test/java/ca/uhn/fhir/jpa/starter/ElasticsearchLastNR4IT.java | Re-enabled test by removing @disabled annotation and adding TestConfig to provide ElasticsearchClient bean for testing |
| src/main/resources/application.yaml | Added application name configuration, refactored Hibernate properties to flat format, added tester configuration, and documented Elasticsearch index prefix option |
| src/main/java/ca/uhn/fhir/jpa/starter/elastic/ElasticsearchConfig.java | New configuration class to create custom ElasticsearchClient bean with authentication and timeout support, conditionally loaded when Elasticsearch is configured |
| src/main/java/ca/uhn/fhir/jpa/starter/elastic/ElasticsearchBootSvcImpl.java | Added index prefix support by accepting AppProperties, renamed constants to base names, and implemented dynamic index name generation with getters |
| src/main/java/ca/uhn/fhir/jpa/starter/common/FhirServerConfigCommon.java | Integrated Elasticsearch index prefix configuration into JpaStorageSettings via setHSearchIndexPrefix |
| src/main/java/ca/uhn/fhir/jpa/starter/AppProperties.java | Added new Elasticsearch nested configuration class with index_prefix property to support custom index naming |
| pom.xml | Updated logback dependencies to 1.5.19 for CVE fix, enabled resource filtering with '@' delimiter for Maven property substitution |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (indexPrefix != null) { | ||
| // Set prefixed index names | ||
| this.observationIndexName = indexPrefix + "-" + OBSERVATION_INDEX_BASE_NAME; | ||
| this.observationCodeIndexName = indexPrefix + "-" + OBSERVATION_CODE_INDEX_BASE_NAME; |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The index prefix implementation has several issues:
- When
index_prefixis empty string (default), indexes will have a leading hyphen (e.g.,-observation_index) - The YAML example shows
"myprefix_"with trailing underscore, but code adds hyphen separator, resulting inmyprefix_-observation_index - No validation for empty/whitespace-only prefixes
Consider this fix:
if (indexPrefix != null && !indexPrefix.trim().isEmpty()) {
String cleanPrefix = indexPrefix.replaceAll("[_-]+$", "");
this.observationIndexName = cleanPrefix + "_" + OBSERVATION_INDEX_BASE_NAME;
this.observationCodeIndexName = cleanPrefix + "_" + OBSERVATION_CODE_INDEX_BASE_NAME;
}And update the YAML comment to: index_prefix: "myprefix" # Prefix for all Elasticsearch indexes (e.g., myprefix_observation_index)
| if (indexPrefix != null) { | |
| // Set prefixed index names | |
| this.observationIndexName = indexPrefix + "-" + OBSERVATION_INDEX_BASE_NAME; | |
| this.observationCodeIndexName = indexPrefix + "-" + OBSERVATION_CODE_INDEX_BASE_NAME; | |
| if (indexPrefix != null && !indexPrefix.trim().isEmpty()) { | |
| // Remove trailing underscores or hyphens from prefix | |
| String cleanPrefix = indexPrefix.replaceAll("[_-]+$", ""); | |
| // Set prefixed index names using underscore separator | |
| this.observationIndexName = cleanPrefix + "_" + OBSERVATION_INDEX_BASE_NAME; | |
| this.observationCodeIndexName = cleanPrefix + "_" + OBSERVATION_CODE_INDEX_BASE_NAME; |
…consistency (spotless:apply)
…consistency (spotless:apply)
…icsearch index names
# Conflicts: # src/test/java/ca/uhn/fhir/jpa/starter/ElasticsearchLastNR4IT.java
…d readability (mvn spotless)
| /** | ||
| * Custom Elasticsearch configuration that creates the ElasticsearchClient bean | ||
| * without the sniffer. This is used when the default Spring Boot autoconfiguration | ||
| * is excluded. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See
| # This exclude is only needed for setups not using Elasticsearch where the elasticsearch sniff is not needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is up with the changes in the application.yaml? Why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change in the applifation.yaml is necessary because of:
- first, configuration of the elasticsearch prefix
- the decomposition of the hibernate properties does not seem to work either with an elasticsearch cluster, nor with an elasticsearch container
- the change to include the home tester in the main configuration can be neglected, but I think that it is confusing not to include it. At least, it should be more clearly documented in the
README.md.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm currently doing some rework on the properties in #893 - where it works fine.
Also - do have a look at https://hapifhir.io/hapi-fhir//apidocs/hapi-fhir-jpaserver-base/src-html/ca/uhn/fhir/jpa/search/elastic/IndexNamePrefixLayoutStrategy.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that class. However, the main objective of the PR is to allow the configuration of the prefix at boot time, because there is no possibility of doing that with a standard spring configuration. The PR uses that class “indirectly”.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I can help in another way with this issue, please let me know.
Summary
This PR adds comprehensive Elasticsearch configuration capabilities, including:
Changes
The changes include 7 commits that enhance the Elasticsearch integration: