fix(search): Fix index builder (#2884)

This commit is contained in:
Dexter Lee 2021-07-15 07:40:52 -07:00 committed by GitHub
parent f7df6959ed
commit 91414a5753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -99,9 +99,10 @@ public class IndexBuilder {
}
log.info("Reindex from {} to {} succeeded", indexName, tempIndexName);
String indexNamePattern = indexName + "_*";
// Check if the original index is aliased or not
GetAliasesResponse aliasesResponse =
searchClient.indices().getAlias(new GetAliasesRequest(indexName), RequestOptions.DEFAULT);
searchClient.indices().getAlias(new GetAliasesRequest(indexName).indices(indexNamePattern), RequestOptions.DEFAULT);
// If not aliased, delete the original index
if (aliasesResponse.getAliases().isEmpty()) {
searchClient.indices().delete(new DeleteIndexRequest().indices(indexName), RequestOptions.DEFAULT);
@ -112,7 +113,7 @@ public class IndexBuilder {
}
// Add alias for the new index
AliasActions removeAction = AliasActions.remove().alias(indexName).index("*");
AliasActions removeAction = AliasActions.remove().alias(indexName).index(indexNamePattern);
AliasActions addAction = AliasActions.add().alias(indexName).index(tempIndexName);
searchClient.indices()
.updateAliases(new IndicesAliasesRequest().addAliasAction(removeAction).addAliasAction(addAction),