Skip to content
Snippets Groups Projects
Commit e12c5277 authored by Zhibin Mai's avatar Zhibin Mai Committed by David Diederich
Browse files

Ensure that createIndexAlias won't affect the creation of index

(cherry picked from commit 3abb9565)
parent d2178ffb
No related branches found
No related tags found
5 merge requests!604Merge Delta changes from M16 master to M18 master,!600Merge Delta changes from M16 master to M18 master,!599Merge Delta changes from M16 to M18 master,!598Merged from M16,!484Cherry-pick 'Create index alias when index is created' into release/0.19
......@@ -52,10 +52,7 @@ import org.springframework.web.context.annotation.RequestScope;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
@Service
@RequestScope
......@@ -309,9 +306,16 @@ public class IndicesServiceImpl implements IndicesService {
private void createIndexAlias(RestHighLevelClient client, String index) {
String kind = this.elasticIndexNameResolver.getKindFromIndexName(index);
String kindWithMajorVersion = getKindWithMajorVersion(kind);
if(!elasticIndexNameResolver.isIndexAliasSupported(kind))
return;
try {
for (String kd : Arrays.asList(kind, kindWithMajorVersion)) {
List<String> kinds = new ArrayList<>();
kinds.add(kind);
if(getKindWithMajorVersion(kind) != null) {
kinds.add(getKindWithMajorVersion(kind));
}
for (String kd : kinds) {
index = elasticIndexNameResolver.getIndexNameFromKind(kd);
String alias = elasticIndexNameResolver.getIndexAliasFromKind(kd);
IndicesAliasesRequest addRequest = new IndicesAliasesRequest();
......@@ -335,7 +339,11 @@ public class IndicesServiceImpl implements IndicesService {
// If kind is common:welldb:wellbore:1.2.0, then kind with major version is common:welldb:wellbore:1.*.*
int idx = kind.lastIndexOf(":");
String version = kind.substring(idx+1);
String majorVersion = version.substring(0, version.indexOf("."));
return String.format("%s:%s.*.*", kind.substring(0, idx), majorVersion);
if(version.indexOf(".") > 0) {
String kindWithoutVersion = kind.substring(0, idx);
String majorVersion = version.substring(0, version.indexOf("."));
return String.format("%s:%s.*.*", kindWithoutVersion, majorVersion);
}
return null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment