Spring Data Elasticsearch 4.1 中弃用了 AliasQuery

AliasQuery is deprecated in Spring Data Elasticsearch 4.1

如何从 Spring Data Elasticsearch 4.0 IndexOperations.addAlias to Spring Data Elasticsearch 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?

official migration guide 没有帮助。

您可以检查测试,例如 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);