Elastic query fallback to db
This commit is contained in:
parent
cbd8041c84
commit
c01fddf534
|
@ -23,7 +23,7 @@ import org.opencdmp.commons.scope.user.UserScope;
|
|||
import org.opencdmp.elastic.data.DescriptionElasticEntity;
|
||||
import org.opencdmp.elastic.data.DmpElasticEntity;
|
||||
import org.opencdmp.elastic.data.nested.NestedDmpElasticEntity;
|
||||
import org.opencdmp.service.elastic.AppElasticProperties;
|
||||
import org.opencdmp.service.elastic.AppElasticConfiguration;
|
||||
import org.opencdmp.service.elastic.ElasticService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
@ -135,16 +135,16 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
|||
}
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final AppElasticProperties appElasticProperties;
|
||||
private final AppElasticConfiguration appElasticConfiguration;
|
||||
private final ElasticService elasticService;
|
||||
private final UserScope userScope;
|
||||
private final TenantScope tenantScope;
|
||||
private final AuthorizationService authService;
|
||||
@Autowired
|
||||
public DescriptionElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticProperties appElasticProperties, ElasticService elasticService, UserScope userScope, TenantScope tenantScope, AuthorizationService authService) {
|
||||
public DescriptionElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticConfiguration appElasticConfiguration, ElasticService elasticService, UserScope userScope, TenantScope tenantScope, AuthorizationService authService) {
|
||||
super(elasticsearchTemplate, elasticProperties);
|
||||
this.queryFactory = queryFactory;
|
||||
this.appElasticProperties = appElasticProperties;
|
||||
this.appElasticConfiguration = appElasticConfiguration;
|
||||
this.elasticService = elasticService;
|
||||
this.userScope = userScope;
|
||||
this.tenantScope = tenantScope;
|
||||
|
@ -306,7 +306,7 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
|||
@Override
|
||||
protected String[] getIndex() {
|
||||
List<String> indexNames = new ArrayList<>();
|
||||
indexNames.add(this.appElasticProperties.getDescriptionIndexName());
|
||||
indexNames.add(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName());
|
||||
try {
|
||||
this.elasticService.ensureDescriptionIndex();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.opencdmp.commons.scope.tenant.TenantScope;
|
|||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.elastic.data.DmpElasticEntity;
|
||||
import org.opencdmp.elastic.data.nested.NestedDescriptionElasticEntity;
|
||||
import org.opencdmp.service.elastic.AppElasticProperties;
|
||||
import org.opencdmp.service.elastic.AppElasticConfiguration;
|
||||
import org.opencdmp.service.elastic.ElasticService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
@ -184,16 +184,16 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
|||
}
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final AppElasticProperties appElasticProperties;
|
||||
private final AppElasticConfiguration appElasticConfiguration;
|
||||
private final ElasticService elasticService;
|
||||
private final UserScope userScope;
|
||||
private final TenantScope tenantScope;
|
||||
private final AuthorizationService authService;
|
||||
@Autowired
|
||||
public DmpElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticProperties appElasticProperties, ElasticService elasticService, UserScope userScope, TenantScope tenantScope, AuthorizationService authService) {
|
||||
public DmpElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticConfiguration appElasticConfiguration, ElasticService elasticService, UserScope userScope, TenantScope tenantScope, AuthorizationService authService) {
|
||||
super(elasticsearchTemplate, elasticProperties);
|
||||
this.queryFactory = queryFactory;
|
||||
this.appElasticProperties = appElasticProperties;
|
||||
this.appElasticConfiguration = appElasticConfiguration;
|
||||
this.elasticService = elasticService;
|
||||
this.userScope = userScope;
|
||||
this.tenantScope = tenantScope;
|
||||
|
@ -369,7 +369,7 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
|||
@Override
|
||||
protected String[] getIndex() {
|
||||
List<String> indexNames = new ArrayList<>();
|
||||
indexNames.add(this.appElasticProperties.getDmpIndexName());
|
||||
indexNames.add(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName());
|
||||
try {
|
||||
this.elasticService.ensureDescriptionIndex();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -5,16 +5,22 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(AppElasticProperties.class)
|
||||
@EnableConfigurationProperties({AppElasticProperties.class, ElasticQueryHelperServiceProperties.class })
|
||||
public class AppElasticConfiguration {
|
||||
private final AppElasticProperties properties;
|
||||
private final AppElasticProperties appElasticProperties;
|
||||
private final ElasticQueryHelperServiceProperties elasticQueryHelperServiceProperties;
|
||||
|
||||
@Autowired
|
||||
public AppElasticConfiguration(AppElasticProperties properties) {
|
||||
this.properties = properties;
|
||||
public AppElasticConfiguration(AppElasticProperties appElasticProperties, ElasticQueryHelperServiceProperties elasticQueryHelperServiceProperties) {
|
||||
this.appElasticProperties = appElasticProperties;
|
||||
this.elasticQueryHelperServiceProperties = elasticQueryHelperServiceProperties;
|
||||
}
|
||||
|
||||
public AppElasticProperties getProperties() {
|
||||
return properties;
|
||||
public AppElasticProperties getAppElasticProperties() {
|
||||
return this.appElasticProperties;
|
||||
}
|
||||
|
||||
public ElasticQueryHelperServiceProperties getElasticQueryHelperServiceProperties() {
|
||||
return this.elasticQueryHelperServiceProperties;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ public class AppElasticProperties {
|
|||
private boolean enableIcuAnalysisPlugin;
|
||||
|
||||
public String getDmpIndexName() {
|
||||
return dmpIndexName;
|
||||
return this.dmpIndexName;
|
||||
}
|
||||
|
||||
public void setDmpIndexName(String dmpIndexName) {
|
||||
|
@ -19,7 +19,7 @@ public class AppElasticProperties {
|
|||
}
|
||||
|
||||
public boolean isEnableIcuAnalysisPlugin() {
|
||||
return enableIcuAnalysisPlugin;
|
||||
return this.enableIcuAnalysisPlugin;
|
||||
}
|
||||
|
||||
public void setEnableIcuAnalysisPlugin(boolean enableIcuAnalysisPlugin) {
|
||||
|
@ -27,7 +27,7 @@ public class AppElasticProperties {
|
|||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
|
@ -35,7 +35,7 @@ public class AppElasticProperties {
|
|||
}
|
||||
|
||||
public String getDescriptionIndexName() {
|
||||
return descriptionIndexName;
|
||||
return this.descriptionIndexName;
|
||||
}
|
||||
|
||||
public void setDescriptionIndexName(String descriptionIndexName) {
|
||||
|
@ -43,7 +43,7 @@ public class AppElasticProperties {
|
|||
}
|
||||
|
||||
public int getResetBatchSize() {
|
||||
return resetBatchSize;
|
||||
return this.resetBatchSize;
|
||||
}
|
||||
|
||||
public void setResetBatchSize(int resetBatchSize) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.tools.data.builder.BuilderFactory;
|
|||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.opencdmp.authorization.AuthorizationFlags;
|
||||
import org.opencdmp.data.DescriptionEntity;
|
||||
import org.opencdmp.data.DmpEntity;
|
||||
|
@ -22,6 +23,7 @@ import org.opencdmp.query.DescriptionQuery;
|
|||
import org.opencdmp.query.DmpQuery;
|
||||
import org.opencdmp.query.lookup.DescriptionLookup;
|
||||
import org.opencdmp.query.lookup.DmpLookup;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
@ -30,14 +32,17 @@ import java.util.function.Function;
|
|||
|
||||
@Service
|
||||
public class ElasticQueryHelperServiceImpl implements ElasticQueryHelperService {
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ElasticQueryHelperServiceImpl.class));
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final BuilderFactory builderFactory;
|
||||
private final ElasticService elasticService;
|
||||
public ElasticQueryHelperServiceImpl(QueryFactory queryFactory, BuilderFactory builderFactory, ElasticService elasticService) {
|
||||
private final AppElasticConfiguration appElasticConfiguration;
|
||||
public ElasticQueryHelperServiceImpl(QueryFactory queryFactory, BuilderFactory builderFactory, ElasticService elasticService, AppElasticConfiguration appElasticConfiguration) {
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
this.elasticService = elasticService;
|
||||
this.appElasticConfiguration = appElasticConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,12 +60,25 @@ public class ElasticQueryHelperServiceImpl implements ElasticQueryHelperService
|
|||
private <M> QueryResult<M> collect(DmpLookup lookup, Function<List<DmpEntity>, List<M>> buildFunc, EnumSet<AuthorizationFlags> flags) {
|
||||
DmpQuery query = null;
|
||||
QueryResult<M> result = new QueryResult<>();
|
||||
boolean elasticFilterUsed = false;
|
||||
if (lookup.useElastic() && this.elasticService.enabled()){
|
||||
List<DmpElasticEntity> elasticResponse = lookup.enrichElastic(this.queryFactory).authorize(flags).collectAs(new BaseFieldSet().ensure(DmpElasticEntity._id));
|
||||
query = this.queryFactory.query(DmpQuery.class).authorize(flags).ids(elasticResponse.stream().map(DmpElasticEntity::getId).toList());
|
||||
query.setOrder(lookup.enrich(this.queryFactory).getOrder());
|
||||
if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(lookup.enrichElastic(this.queryFactory).authorize(flags).count());
|
||||
} else {
|
||||
try {
|
||||
List<DmpElasticEntity> elasticResponse = lookup.enrichElastic(this.queryFactory).authorize(flags).collectAs(new BaseFieldSet().ensure(DmpElasticEntity._id));
|
||||
query = this.queryFactory.query(DmpQuery.class).authorize(flags).ids(elasticResponse.stream().map(DmpElasticEntity::getId).toList());
|
||||
query.setOrder(lookup.enrich(this.queryFactory).getOrder());
|
||||
if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(lookup.enrichElastic(this.queryFactory).authorize(flags).count());
|
||||
elasticFilterUsed = true;
|
||||
} catch (Exception e){
|
||||
elasticFilterUsed = false;
|
||||
if (this.appElasticConfiguration.getElasticQueryHelperServiceProperties().getEnableDbFallback()) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!elasticFilterUsed) {
|
||||
query = lookup.enrich(this.queryFactory).disableTracking().authorize(flags);
|
||||
if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(query.count());
|
||||
}
|
||||
|
@ -74,10 +92,17 @@ public class ElasticQueryHelperServiceImpl implements ElasticQueryHelperService
|
|||
public long count(DmpLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags) {
|
||||
EnumSet<AuthorizationFlags> flags = authorizationFlags == null ? EnumSet.of(AuthorizationFlags.None) : authorizationFlags;
|
||||
if (lookup.useElastic() && this.elasticService.enabled()){
|
||||
return lookup.enrichElastic(this.queryFactory).authorize(flags).count();
|
||||
} else {
|
||||
return lookup.enrich(this.queryFactory).authorize(flags).count();
|
||||
try {
|
||||
return lookup.enrichElastic(this.queryFactory).authorize(flags).count();
|
||||
} catch (Exception e){
|
||||
if (this.appElasticConfiguration.getElasticQueryHelperServiceProperties().getEnableDbFallback()) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lookup.enrich(this.queryFactory).authorize(flags).count();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -96,12 +121,26 @@ public class ElasticQueryHelperServiceImpl implements ElasticQueryHelperService
|
|||
private <M> QueryResult<M> collect(DescriptionLookup lookup, Function<List<DescriptionEntity>, List<M>> buildFunc, EnumSet<AuthorizationFlags> flags) {
|
||||
DescriptionQuery query = null;
|
||||
QueryResult<M> result = new QueryResult<>();
|
||||
boolean elasticFilterUsed = false;
|
||||
if (lookup.useElastic() && this.elasticService.enabled()){
|
||||
List<DescriptionElasticEntity> elasticResponse = lookup.enrichElastic(this.queryFactory).authorize(flags).collectAs(new BaseFieldSet().ensure(DescriptionElasticEntity._id));
|
||||
query = this.queryFactory.query(DescriptionQuery.class).authorize(flags).ids(elasticResponse.stream().map(DescriptionElasticEntity::getId).toList());
|
||||
query.setOrder(lookup.enrich(this.queryFactory).getOrder());
|
||||
if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(lookup.enrichElastic(this.queryFactory).authorize(flags).count());
|
||||
} else {
|
||||
|
||||
try {
|
||||
List<DescriptionElasticEntity> elasticResponse = lookup.enrichElastic(this.queryFactory).authorize(flags).collectAs(new BaseFieldSet().ensure(DescriptionElasticEntity._id));
|
||||
query = this.queryFactory.query(DescriptionQuery.class).authorize(flags).ids(elasticResponse.stream().map(DescriptionElasticEntity::getId).toList());
|
||||
query.setOrder(lookup.enrich(this.queryFactory).getOrder());
|
||||
if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(lookup.enrichElastic(this.queryFactory).authorize(flags).count());
|
||||
elasticFilterUsed = true;
|
||||
} catch (Exception e){
|
||||
elasticFilterUsed = false;
|
||||
if (this.appElasticConfiguration.getElasticQueryHelperServiceProperties().getEnableDbFallback()) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (!elasticFilterUsed) {
|
||||
query = lookup.enrich(this.queryFactory).disableTracking().authorize(flags);
|
||||
if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(query.count());
|
||||
}
|
||||
|
@ -115,9 +154,16 @@ public class ElasticQueryHelperServiceImpl implements ElasticQueryHelperService
|
|||
public long count(DescriptionLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags) {
|
||||
EnumSet<AuthorizationFlags> flags = authorizationFlags == null ? EnumSet.of(AuthorizationFlags.None) : authorizationFlags;
|
||||
if (lookup.useElastic() && this.elasticService.enabled()){
|
||||
return lookup.enrichElastic(this.queryFactory).authorize(flags).count();
|
||||
} else {
|
||||
return lookup.enrich(this.queryFactory).authorize(flags).count();
|
||||
try {
|
||||
return lookup.enrichElastic(this.queryFactory).authorize(flags).count();
|
||||
} catch (Exception e){
|
||||
if (this.appElasticConfiguration.getElasticQueryHelperServiceProperties().getEnableDbFallback()) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lookup.enrich(this.queryFactory).authorize(flags).count();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.opencdmp.service.elastic;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "elastic-query-helper")
|
||||
public class ElasticQueryHelperServiceProperties {
|
||||
private boolean enableDbFallback;
|
||||
|
||||
public boolean getEnableDbFallback() {
|
||||
return this.enableDbFallback;
|
||||
}
|
||||
|
||||
public void setEnableDbFallback(boolean enableDbFallback) {
|
||||
this.enableDbFallback = enableDbFallback;
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ import java.util.Map;
|
|||
@Service
|
||||
public class ElasticServiceImpl implements ElasticService {
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpBlueprintServiceImpl.class));
|
||||
public final AppElasticProperties appElasticProperties;
|
||||
public final AppElasticConfiguration appElasticConfiguration;
|
||||
private final ElasticsearchClient restHighLevelClient;
|
||||
private final ElasticsearchTemplate elasticsearchTemplate;
|
||||
private final QueryFactory queryFactory;
|
||||
|
@ -55,8 +55,8 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
private final MessageSource messageSource;
|
||||
private final AuthorizationService authorizationService;
|
||||
|
||||
public ElasticServiceImpl(AppElasticProperties appElasticProperties, ElasticsearchClient restHighLevelClient, ElasticsearchTemplate elasticsearchTemplate, QueryFactory queryFactory, BuilderFactory builderFactory, TenantEntityManager entityManager, MessageSource messageSource, AuthorizationService authorizationService) {
|
||||
this.appElasticProperties = appElasticProperties;
|
||||
public ElasticServiceImpl(AppElasticConfiguration appElasticConfiguration, ElasticsearchClient restHighLevelClient, ElasticsearchTemplate elasticsearchTemplate, QueryFactory queryFactory, BuilderFactory builderFactory, TenantEntityManager entityManager, MessageSource messageSource, AuthorizationService authorizationService) {
|
||||
this.appElasticConfiguration = appElasticConfiguration;
|
||||
this.restHighLevelClient = restHighLevelClient;
|
||||
this.elasticsearchTemplate = elasticsearchTemplate;
|
||||
this.queryFactory = queryFactory;
|
||||
|
@ -68,20 +68,20 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
|
||||
@Override
|
||||
public boolean enabled() {
|
||||
return this.appElasticProperties.isEnabled();
|
||||
return this.appElasticConfiguration.getAppElasticProperties().isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsDmpIndex() throws IOException {
|
||||
if (!this.enabled()) return false;
|
||||
return this.restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticProperties.getDmpIndexName()).includeDefaults(true).build()).value();
|
||||
return this.restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()).includeDefaults(true).build()).value();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean existsDescriptionIndex() throws IOException {
|
||||
if (!this.enabled()) return false;
|
||||
return this.restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticProperties.getDescriptionIndexName()).includeDefaults(true).build()).value();
|
||||
return this.restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()).includeDefaults(true).build()).value();
|
||||
}
|
||||
|
||||
//region ensure index
|
||||
|
@ -92,7 +92,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
boolean exists = this.existsDmpIndex();
|
||||
if (exists) return ;
|
||||
|
||||
this.ensureIndex(this.appElasticProperties.getDmpIndexName(), this.createDmpTemplatePropertyMap());
|
||||
this.ensureIndex(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName(), this.createDmpTemplatePropertyMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -100,7 +100,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
if (!this.enabled()) return ;
|
||||
boolean exists = this.existsDescriptionIndex();
|
||||
if (exists) return ;
|
||||
this.ensureIndex(this.appElasticProperties.getDescriptionIndexName(), this.createDescriptionTemplatePropertyMap());
|
||||
this.ensureIndex(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName(), this.createDescriptionTemplatePropertyMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -120,7 +120,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
indexSettingsAnalysis.filter("english_stemmer", ((tf) -> tf.definition(tfdb -> tfdb.stemmer(stemmerBuilder -> stemmerBuilder.language("english")))))
|
||||
.filter("english_stop", tf -> tf.definition(tfdb -> tfdb.stop(stopTokenBuilder -> stopTokenBuilder)));
|
||||
|
||||
if (this.appElasticProperties.isEnableIcuAnalysisPlugin()){
|
||||
if (this.appElasticConfiguration.getAppElasticProperties().isEnableIcuAnalysisPlugin()){
|
||||
indexSettingsAnalysis.analyzer("icu_analyzer_text", ab -> ab.custom(x-> x.filter("icu_folding", "english_stop", "english_stemmer").tokenizer("icu_tokenizer")));
|
||||
} else {
|
||||
indexSettingsAnalysis.analyzer("icu_analyzer_text", ab -> ab.custom(x-> x.filter("icu_folding", "english_stop", "english_stemmer").tokenizer("standard")));
|
||||
|
@ -291,23 +291,23 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
this.ensureIndexes();
|
||||
|
||||
DmpElasticEntity dmpElasticEntity = this.builderFactory.builder(DmpElasticBuilder.class).build(dmp);
|
||||
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()));
|
||||
List<DescriptionElasticEntity> descriptions = this.builderFactory.builder(DescriptionElasticBuilder.class).build(this.queryFactory.query(DescriptionQuery.class).disableTracking().isActive(IsActive.Active).dmpSubQuery(this.queryFactory.query(DmpQuery.class).ids(dmp.getId())).collect());
|
||||
this.elasticsearchTemplate.save(descriptions, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
this.elasticsearchTemplate.save(descriptions, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDmp(DmpEntity dmp) throws IOException {
|
||||
if (!this.enabled()) return;
|
||||
this.ensureIndexes();
|
||||
DmpElasticEntity dmpElasticEntity = this.elasticsearchTemplate.get(dmp.getId().toString(),DmpElasticEntity.class, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
DmpElasticEntity dmpElasticEntity = this.elasticsearchTemplate.get(dmp.getId().toString(),DmpElasticEntity.class, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()));
|
||||
if (dmpElasticEntity == null) return;
|
||||
this.elasticsearchTemplate.delete(dmpElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
this.elasticsearchTemplate.delete(dmpElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()));
|
||||
List<DescriptionEntity> descriptions = this.queryFactory.query(DescriptionQuery.class).dmpSubQuery(this.queryFactory.query(DmpQuery.class).disableTracking().ids(dmp.getId())).collectAs(new BaseFieldSet().ensure(Description._id));
|
||||
for (DescriptionEntity description: descriptions) {
|
||||
DescriptionElasticEntity descriptionElasticEntity = this.elasticsearchTemplate.get(description.getId().toString(), DescriptionElasticEntity.class, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
DescriptionElasticEntity descriptionElasticEntity = this.elasticsearchTemplate.get(description.getId().toString(), DescriptionElasticEntity.class, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
if (descriptionElasticEntity == null) continue;
|
||||
this.elasticsearchTemplate.delete(descriptionElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
this.elasticsearchTemplate.delete(descriptionElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,12 +317,12 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
this.ensureIndexes();
|
||||
|
||||
DescriptionElasticEntity descriptionElasticEntity = this.builderFactory.builder(DescriptionElasticBuilder.class).build(description);
|
||||
this.elasticsearchTemplate.save(descriptionElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
this.elasticsearchTemplate.save(descriptionElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, description.getDmpId(), true);
|
||||
if (dmpEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{description.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
if (dmpEntity.getIsActive().equals(IsActive.Active)) {
|
||||
DmpElasticEntity dmpElasticEntity = this.builderFactory.builder(DmpElasticBuilder.class).build(dmpEntity);
|
||||
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -331,15 +331,15 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
if (!this.enabled()) return;
|
||||
this.ensureIndexes();
|
||||
|
||||
DescriptionElasticEntity descriptionElasticEntity = this.elasticsearchTemplate.get(description.getId().toString(), DescriptionElasticEntity.class, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
DescriptionElasticEntity descriptionElasticEntity = this.elasticsearchTemplate.get(description.getId().toString(), DescriptionElasticEntity.class, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
if (descriptionElasticEntity == null) return;
|
||||
this.elasticsearchTemplate.delete(descriptionElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
this.elasticsearchTemplate.delete(descriptionElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
|
||||
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, description.getDmpId(), true);
|
||||
if (dmpEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{description.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
if (dmpEntity.getIsActive().equals(IsActive.Active)) {
|
||||
DmpElasticEntity dmpElasticEntity = this.builderFactory.builder(DmpElasticBuilder.class).build(dmpEntity);
|
||||
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
boolean exists = this.existsDmpIndex();
|
||||
if (!exists) return ;
|
||||
|
||||
this.restHighLevelClient.indices().delete(new DeleteIndexRequest.Builder().index(this.appElasticProperties.getDmpIndexName()).build());
|
||||
this.restHighLevelClient.indices().delete(new DeleteIndexRequest.Builder().index(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -367,7 +367,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
if (!this.enabled()) return;
|
||||
boolean exists = this.existsDescriptionIndex();
|
||||
if (!exists) return ;
|
||||
this.restHighLevelClient.indices().delete(new DeleteIndexRequest.Builder().index(this.appElasticProperties.getDescriptionIndexName()).build());
|
||||
this.restHighLevelClient.indices().delete(new DeleteIndexRequest.Builder().index(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -382,7 +382,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
try {
|
||||
this.entityManager.disableTenantFilters();
|
||||
int page = 0;
|
||||
int pageSize = this.appElasticProperties.getResetBatchSize();
|
||||
int pageSize = this.appElasticConfiguration.getAppElasticProperties().getResetBatchSize();
|
||||
List<DmpEntity> items;
|
||||
do {
|
||||
DmpQuery query = this.queryFactory.query(DmpQuery.class).disableTracking();
|
||||
|
@ -392,7 +392,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
items = query.collect();
|
||||
if (items != null && !items.isEmpty()) {
|
||||
List<DmpElasticEntity> elasticEntities = this.builderFactory.builder(DmpElasticBuilder.class).build(items);
|
||||
this.elasticsearchTemplate.save(elasticEntities, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
this.elasticsearchTemplate.save(elasticEntities, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()));
|
||||
page++;
|
||||
}
|
||||
} while (items != null && !items.isEmpty());
|
||||
|
@ -414,7 +414,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
this.entityManager.disableTenantFilters();
|
||||
|
||||
int page = 0;
|
||||
int pageSize = this.appElasticProperties.getResetBatchSize();
|
||||
int pageSize = this.appElasticConfiguration.getAppElasticProperties().getResetBatchSize();
|
||||
List<DescriptionEntity> items;
|
||||
do {
|
||||
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).disableTracking();
|
||||
|
@ -424,7 +424,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
items = query.collect();
|
||||
if (items != null && !items.isEmpty()) {
|
||||
List<DescriptionElasticEntity> elasticEntities = this.builderFactory.builder(DescriptionElasticBuilder.class).build(items);
|
||||
this.elasticsearchTemplate.save(elasticEntities, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
this.elasticsearchTemplate.save(elasticEntities, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
page++;
|
||||
}
|
||||
} while (items != null && !items.isEmpty());
|
||||
|
|
|
@ -4,3 +4,5 @@ elastic:
|
|||
- classpath:certificates/elasticsearch_dev04.crt
|
||||
app-elastic:
|
||||
enableIcuAnalysisPlugin: true
|
||||
elastic-query-helper:
|
||||
enableDbFallback: false
|
|
@ -19,3 +19,5 @@ app-elastic:
|
|||
descriptionIndexName: ${ELASTIC_DESCRIPTION_INDEX}
|
||||
enableIcuAnalysisPlugin: false
|
||||
resetBatchSize: 1000
|
||||
elastic-query-helper:
|
||||
enableDbFallback: true
|
Loading…
Reference in New Issue