diff --git a/jetlinks-components/elasticsearch-component/src/main/java/org/jetlinks/community/elastic/search/index/strategies/TemplateElasticSearchIndexStrategy.java b/jetlinks-components/elasticsearch-component/src/main/java/org/jetlinks/community/elastic/search/index/strategies/TemplateElasticSearchIndexStrategy.java index c01087897..8195aafb9 100755 --- a/jetlinks-components/elasticsearch-component/src/main/java/org/jetlinks/community/elastic/search/index/strategies/TemplateElasticSearchIndexStrategy.java +++ b/jetlinks-components/elasticsearch-component/src/main/java/org/jetlinks/community/elastic/search/index/strategies/TemplateElasticSearchIndexStrategy.java @@ -1,5 +1,6 @@ package org.jetlinks.community.elastic.search.index.strategies; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.alias.Alias; @@ -15,6 +16,7 @@ import java.util.List; import java.util.Map; +@Slf4j public abstract class TemplateElasticSearchIndexStrategy extends AbstractElasticSearchIndexStrategy { public TemplateElasticSearchIndexStrategy(String id, ReactiveElasticsearchClient client, ElasticSearchIndexProperties properties) { @@ -43,11 +45,16 @@ public String getIndexForSearch(String index) { @Override public Mono putIndex(ElasticSearchIndexMetadata metadata) { - + String saveIndex = getIndexForSave(metadata.getIndex()); return client .putTemplate(createIndexTemplateRequest(metadata)) //修改当前索引 - .then(doPutIndex(metadata.newIndexName(getIndexForSave(metadata.getIndex())), true)) + .then(doPutIndex(metadata.newIndexName(saveIndex), true) + //忽略修改索引错误 + .onErrorResume(err -> { + log.warn("Update Index[{}] Mapping error", saveIndex, err); + return Mono.empty(); + })) .thenReturn(metadata.newIndexName(wrapIndex(metadata.getIndex()))); } @@ -59,6 +66,7 @@ protected PutIndexTemplateRequest createIndexTemplateRequest(ElasticSearchIndexM Map mappingConfig = new HashMap<>(); mappingConfig.put("properties", createElasticProperties(metadata.getProperties())); mappingConfig.put("dynamic_templates", createDynamicTemplates()); + mappingConfig.put("_source", Collections.singletonMap("enabled", true)); if (client.serverVersion().after(Version.V_7_0_0)) { request.mapping(mappingConfig); } else {