首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DIfficulty向DynamoDB中的现有表添加全局辅助索引

DIfficulty向DynamoDB中的现有表添加全局辅助索引
EN

Stack Overflow用户
提问于 2015-07-29 21:45:16
回答 1查看 439关注 0票数 1

表: EmailMessages

EntityId - HashKey : String

Id - RangeKey : String

名称-字符串

状态字符串

我想为身份做一个GlobalSecondaryIndex

代码语言:javascript
复制
var request = new UpdateTableRequest
        {
            TableName = "EmailMessages",
            GlobalSecondaryIndexUpdates = new List<GlobalSecondaryIndexUpdate>
            {
                new GlobalSecondaryIndexUpdate
                {
                    Create = new CreateGlobalSecondaryIndexAction
                    {
                        IndexName = "GSI_EmailMessages_Status",
                        KeySchema = new List<KeySchemaElement>
                        {
                            new KeySchemaElement("Status", KeyType.HASH)
                        }
                    }
                }
            }
        };

        var client = DynamoDBManager.DBFactory.GetClient();

        client.UpdateTable(request);

然而,我得到的返回错误是一个没有返回文本的500错误,所以我不确定我需要纠正什么才能使它工作。我已经仔细研究了文档,似乎在为现有表创建GSI方面找不到什么帮助。任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-30 14:56:06

我设法解决了我的问题。结果我需要更多的代码。我将发布我的解决方案,以防其他人遇到类似的问题,因为似乎还没有为Dynamo提供多少资源。请注意,我的读写能力非常低,因为这是一个开发环境。你可能会考虑根据你的需要来提高你的

代码语言:javascript
复制
var request = new UpdateTableRequest
        {
            TableName = "EmailMessage",
            AttributeDefinitions = new List<AttributeDefinition>
            {
                new AttributeDefinition
                {
                    AttributeName = "Status",
                    AttributeType = ScalarAttributeType.S
                }
            },
            GlobalSecondaryIndexUpdates = new List<GlobalSecondaryIndexUpdate>
            {
                new GlobalSecondaryIndexUpdate
                {
                    Create = new CreateGlobalSecondaryIndexAction
                    {
                        IndexName = "GSI_EmailMessage_Status",
                        KeySchema = new List<KeySchemaElement>
                        {
                            new KeySchemaElement("Status", KeyType.HASH)
                        },
                        Projection = new Projection
                        {
                            ProjectionType = ProjectionType.ALL
                        },
                        ProvisionedThroughput = new ProvisionedThroughput
                        {
                            ReadCapacityUnits = 4,
                            WriteCapacityUnits = 1,
                        }
                    }
                }
            }
        };

        var client = DynamoDBManager.DBFactory.GetClient();

        client.UpdateTable(request);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31711749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档