是否可以用java编程在现有表上创建GSI?我知道在使用创建新表时这是可能的
dynamoDB.createTable(new CreateTableRequest().withGlobalSecondaryIndexes(index));
我还知道,在从web创建表之后创建索引是可能的。
您需要使用GlobalSecondaryIndexUpdate方法来完成此操作,如下所述:https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GlobalSecondaryIndexUpdate.html
它应该看起来像这个
CreateGlobalSecondaryIndexAction action = CreateGlobalSecondaryIndexAction
.builder()
.indexName("index-name")
.keySchema(theSchema)
.build();
GlobalSecondaryIndexUpdate index = GlobalSecondaryIndexUpdate
.builder()
.create(action)
.build();
UpdateTableRequest request = UpdateTableRequest
.builder()
.tableName("table-name")
.globalSecondaryIndexUpdates(index)
.build();
dynamoDbClient.updateTable(request);