|
@@ -37,8 +37,6 @@ import org.elasticsearch.common.util.set.Sets;
|
|
|
import org.elasticsearch.core.Nullable;
|
|
|
import org.elasticsearch.core.TimeValue;
|
|
|
import org.elasticsearch.core.Tuple;
|
|
|
-import org.elasticsearch.index.CloseUtils;
|
|
|
-import org.elasticsearch.index.Index;
|
|
|
import org.elasticsearch.index.IndexService;
|
|
|
import org.elasticsearch.index.IndexSettingProvider;
|
|
|
import org.elasticsearch.index.IndexSettingProviders;
|
|
@@ -82,7 +80,6 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
import static java.util.Collections.emptyMap;
|
|
|
import static org.elasticsearch.cluster.metadata.MetadataCreateDataStreamService.validateTimestampFieldMapping;
|
|
|
-import static org.elasticsearch.indices.cluster.IndexRemovalReason.NO_LONGER_ASSIGNED;
|
|
|
|
|
|
/**
|
|
|
* Service responsible for submitting index templates updates
|
|
@@ -1861,45 +1858,28 @@ public class MetadataIndexTemplateService {
|
|
|
settings = Settings.EMPTY;
|
|
|
}
|
|
|
|
|
|
- Index createdIndex = null;
|
|
|
final String temporaryIndexName = UUIDs.randomBase64UUID();
|
|
|
- try {
|
|
|
- // use the provided values, otherwise just pick valid dummy values
|
|
|
- int dummyPartitionSize = IndexMetadata.INDEX_ROUTING_PARTITION_SIZE_SETTING.get(settings);
|
|
|
- int dummyShards = settings.getAsInt(
|
|
|
- IndexMetadata.SETTING_NUMBER_OF_SHARDS,
|
|
|
- dummyPartitionSize == 1 ? 1 : dummyPartitionSize + 1
|
|
|
- );
|
|
|
- int shardReplicas = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0);
|
|
|
-
|
|
|
- // create index service for parsing and validating "mappings"
|
|
|
- Settings dummySettings = Settings.builder()
|
|
|
- .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
|
|
|
- .put(settings)
|
|
|
- .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, dummyShards)
|
|
|
- .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, shardReplicas)
|
|
|
- .put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
|
|
- .build();
|
|
|
+ int dummyPartitionSize = IndexMetadata.INDEX_ROUTING_PARTITION_SIZE_SETTING.get(settings);
|
|
|
+ int dummyShards = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_SHARDS, dummyPartitionSize == 1 ? 1 : dummyPartitionSize + 1);
|
|
|
+ int shardReplicas = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0);
|
|
|
|
|
|
- final IndexMetadata tmpIndexMetadata = IndexMetadata.builder(temporaryIndexName).settings(dummySettings).build();
|
|
|
- IndexService dummyIndexService = indicesService.createIndex(tmpIndexMetadata, Collections.emptyList(), false);
|
|
|
- createdIndex = dummyIndexService.index();
|
|
|
+ // create index service for parsing and validating "mappings"
|
|
|
+ Settings dummySettings = Settings.builder()
|
|
|
+ .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
|
|
|
+ .put(settings)
|
|
|
+ .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, dummyShards)
|
|
|
+ .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, shardReplicas)
|
|
|
+ .put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
|
|
+ .build();
|
|
|
|
|
|
+ final IndexMetadata tmpIndexMetadata = IndexMetadata.builder(temporaryIndexName).settings(dummySettings).build();
|
|
|
+
|
|
|
+ indicesService.withTempIndexService(tmpIndexMetadata, dummyIndexService -> {
|
|
|
if (mappings != null) {
|
|
|
dummyIndexService.mapperService().merge(MapperService.SINGLE_MAPPING_NAME, mappings, MergeReason.INDEX_TEMPLATE);
|
|
|
}
|
|
|
-
|
|
|
- } finally {
|
|
|
- if (createdIndex != null) {
|
|
|
- indicesService.removeIndex(
|
|
|
- createdIndex,
|
|
|
- NO_LONGER_ASSIGNED,
|
|
|
- " created for parsing template mapping",
|
|
|
- CloseUtils.NO_SHARDS_CREATED_EXECUTOR,
|
|
|
- ActionListener.noop()
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
+ return null;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private void validate(String name, ComponentTemplate template) {
|