Added support for $lastn operation and fixed Elasticsearch indexing.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package ca.uhn.fhir.jpa.starter;
|
||||
|
||||
import ca.uhn.fhir.jpa.search.elastic.ElasticsearchHibernatePropertiesBuilder;
|
||||
import org.hibernate.search.elasticsearch.cfg.ElasticsearchIndexStatus;
|
||||
import org.hibernate.search.elasticsearch.cfg.IndexSchemaManagementStrategy;
|
||||
import org.springframework.core.env.CompositePropertySource;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.EnumerablePropertySource;
|
||||
@@ -35,9 +38,66 @@ public class EnvironmentHelper {
|
||||
properties.put(values[0], values[1]);
|
||||
});
|
||||
}
|
||||
|
||||
if (environment.getProperty("elasticsearch.enabled", Boolean.class) != null
|
||||
&& environment.getProperty("elasticsearch.enabled", Boolean.class) == true ){
|
||||
ElasticsearchHibernatePropertiesBuilder builder = new ElasticsearchHibernatePropertiesBuilder();
|
||||
ElasticsearchIndexStatus requiredIndexStatus = environment.getProperty("elasticsearch.required_index_status", ElasticsearchIndexStatus.class);
|
||||
if (requiredIndexStatus == null) {
|
||||
builder.setRequiredIndexStatus(ElasticsearchIndexStatus.YELLOW);
|
||||
} else {
|
||||
builder.setRequiredIndexStatus(requiredIndexStatus);
|
||||
}
|
||||
|
||||
builder.setRestUrl(getElasticsearchServerUrl(environment));
|
||||
builder.setUsername(getElasticsearchServerUsername(environment));
|
||||
builder.setPassword(getElasticsearchServerPassword(environment));
|
||||
IndexSchemaManagementStrategy indexSchemaManagementStrategy = environment.getProperty("elasticsearch.schema_management_strategy", IndexSchemaManagementStrategy.class);
|
||||
if (indexSchemaManagementStrategy == null) {
|
||||
builder.setIndexSchemaManagementStrategy(IndexSchemaManagementStrategy.CREATE);
|
||||
} else {
|
||||
builder.setIndexSchemaManagementStrategy(indexSchemaManagementStrategy);
|
||||
}
|
||||
// pretty_print_json_log: false
|
||||
Boolean refreshAfterWrite = environment.getProperty("elasticsearch.debug.refresh_after_write", Boolean.class);
|
||||
if (refreshAfterWrite == null) {
|
||||
builder.setDebugRefreshAfterWrite(false);
|
||||
} else {
|
||||
builder.setDebugRefreshAfterWrite(refreshAfterWrite);
|
||||
}
|
||||
// pretty_print_json_log: false
|
||||
Boolean prettyPrintJsonLog = environment.getProperty("elasticsearch.debug.pretty_print_json_log", Boolean.class);
|
||||
if (prettyPrintJsonLog == null) {
|
||||
builder.setDebugPrettyPrintJsonLog(false);
|
||||
} else {
|
||||
builder.setDebugPrettyPrintJsonLog(prettyPrintJsonLog);
|
||||
}
|
||||
builder.apply(properties);
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
public static String getElasticsearchServerUrl(ConfigurableEnvironment environment) {
|
||||
return environment.getProperty("elasticsearch.rest_url", String.class);
|
||||
}
|
||||
|
||||
public static String getElasticsearchServerUsername(ConfigurableEnvironment environment) {
|
||||
return environment.getProperty("elasticsearch.username");
|
||||
}
|
||||
|
||||
public static String getElasticsearchServerPassword(ConfigurableEnvironment environment) {
|
||||
return environment.getProperty("elasticsearch.password");
|
||||
}
|
||||
|
||||
public static Boolean isElasticsearchEnabled(ConfigurableEnvironment environment) {
|
||||
if (environment.getProperty("elasticsearch.enabled", Boolean.class) != null) {
|
||||
return environment.getProperty("elasticsearch.enabled", Boolean.class);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Object> getPropertiesStartingWith(ConfigurableEnvironment aEnv,
|
||||
String aKeyPrefix) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user