如何从Spring Data Elasticsearch 4.0 IndexOperations.addAlias迁移到Spring Data Elisticsearch 4.1 IndexOperations.alias?
我有以下方法:
@Autowired ElasticsearchOperations operations;
public boolean addAlias(String indexName, String aliasName) {
IndexCoordinates index = IndexCoordinates.of(indexName);
IndexOperations indexOperations = operations.indexOps(index);
// Create an alias
return indexOperations.addAlias(new AliasQuery(aliasName));
}
如何将其迁移到新的AliasActions API?
官方的移民指南没有帮助。
您可以检查测试,例如在https://github.com/spring-projects/spring-data-elasticsearch/blob/master/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java#L2784-L2830
AliasActions aliasActions = new AliasActions();
aliasActions.add(new AliasAction.Add(AliasActionParameters.builder()
.withIndices(indexOperations.getIndexCoordinates().getIndexNames()).withAliases("aliasA", "aliasB").build()));
indexOperations.alias(aliasActions);