在java中创建表后创建dynamodb全局二级索引

ecfdbz9o  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(477)

是否可以从java以编程方式在现有表上创建gsi?我知道在使用

  1. dynamoDB.createTable(new CreateTableRequest().withGlobalSecondaryIndexes(index));

我还知道,从web创建表之后,可以创建索引。

rnmwe5a2

rnmwe5a21#

您需要使用globalsecondaryindexupdate方法来执行此操作,如下所述:https://docs.aws.amazon.com/amazondynamodb/latest/apireference/api_globalsecondaryindexupdate.html
应该是这样的

  1. CreateGlobalSecondaryIndexAction action = CreateGlobalSecondaryIndexAction
  2. .builder()
  3. .indexName("index-name")
  4. .keySchema(theSchema)
  5. .build();
  6. GlobalSecondaryIndexUpdate index = GlobalSecondaryIndexUpdate
  7. .builder()
  8. .create(action)
  9. .build();
  10. UpdateTableRequest request = UpdateTableRequest
  11. .builder()
  12. .tableName("table-name")
  13. .globalSecondaryIndexUpdates(index)
  14. .build();
  15. dynamoDbClient.updateTable(request);
展开查看全部

相关问题