Skip to content

Conversation

@darthcav
Copy link

Summary

This PR adds comprehensive Elasticsearch configuration capabilities, including:

  • Index prefix configuration for Elasticsearch indices
  • Custom Elasticsearch client configuration bean
  • Application name and tester configuration
  • Reindexing resources upon search parameter change configuration
  • Logback dependency updates for security fixes
  • Resource filtering enablement

Changes

The changes include 7 commits that enhance the Elasticsearch integration:

  1. Add Elasticsearch configuration section to application.yaml
  2. Add configuration for reindexing resources upon search parameter change
  3. Add Elasticsearch client configuration for testing
  4. Merge latest changes from master
  5. Update logback dependencies for security issue and enable resource filtering
  6. Add application name and tester configuration, refactor hibernate properties
  7. Add custom Elasticsearch configuration to create ElasticsearchClient bean
  8. Add index prefix configuration for Elasticsearch indices

@jkiddo jkiddo requested a review from Copilot November 16, 2025 13:04
Copilot finished reviewing on behalf of jkiddo November 16, 2025 13:08
Copy link
Contributor

Copilot AI left a 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.

Comment on lines 69 to 72
if (indexPrefix != null) {
// Set prefixed index names
this.observationIndexName = indexPrefix + "-" + OBSERVATION_INDEX_BASE_NAME;
this.observationCodeIndexName = indexPrefix + "-" + OBSERVATION_CODE_INDEX_BASE_NAME;
Copy link

Copilot AI Nov 16, 2025

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:

  1. When index_prefix is empty string (default), indexes will have a leading hyphen (e.g., -observation_index)
  2. The YAML example shows "myprefix_" with trailing underscore, but code adds hyphen separator, resulting in myprefix_-observation_index
  3. 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)

Suggested change
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;

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +24
/**
* Custom Elasticsearch configuration that creates the ElasticsearchClient bean
* without the sniffer. This is used when the default Spring Boot autoconfiguration
* is excluded.
*/
Copy link
Collaborator

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.

Copy link
Collaborator

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?

Copy link
Author

@darthcav darthcav Nov 24, 2025

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.

Copy link
Collaborator

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

Copy link
Author

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”.

Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants