首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >查询DynamoDb全局辅助索引

查询DynamoDb全局辅助索引
EN

Stack Overflow用户
提问于 2021-10-01 14:47:34
回答 1查看 783关注 0票数 0

我正在本地试用dynamodb,并得到了下表:

代码语言:javascript
复制
"Table": {
    "AttributeDefinitions": [
        {
            "AttributeName": "hashKey",
            "AttributeType": "S"
        },
        {
            "AttributeName": "sortKey",
            "AttributeType": "S"
        },
        {
            "AttributeName": "full_json",
            "AttributeType": "S"
        }
    ],
    "TableName": "local",
    "KeySchema": [
        {
            "AttributeName": "hashKey",
            "KeyType": "HASH"
        },
        {
            "AttributeName": "sortKey",
            "KeyType": "RANGE"
        }
    ],
    "TableStatus": "ACTIVE",
    "CreationDateTime": "2021-10-01T15:18:04.413000+02:00",
    "ProvisionedThroughput": {
        "LastIncreaseDateTime": "1970-01-01T01:00:00+01:00",
        "LastDecreaseDateTime": "1970-01-01T01:00:00+01:00",
        "NumberOfDecreasesToday": 0,
        "ReadCapacityUnits": 5,
        "WriteCapacityUnits": 1
    },
    "TableSizeBytes": 1066813,
    "ItemCount": 23,
    "TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/local",
    "GlobalSecondaryIndexes": [
        {
            "IndexName": "sortKeyIndex",
            "KeySchema": [
                {
                    "AttributeName": "sortKey",
                    "KeyType": "HASH"
                }
            ],
            "Projection": {
                "ProjectionType": "ALL"
            },
            "IndexStatus": "ACTIVE",
            "ProvisionedThroughput": {
                "ReadCapacityUnits": 10,
                "WriteCapacityUnits": 1
            },
            "IndexSizeBytes": 1066813,
            "ItemCount": 23,
            "IndexArn": "arn:aws:dynamodb:ddblocal:000000000000:table/local/index/sortKeyIndex"
        }
    ]
}

我想用这样的Java查询它:

代码语言:javascript
复制
Index index = table.getIndex("sortKeyIndex");
ItemCollection<QueryOutcome> items2 = null;
QuerySpec querySpec = new QuerySpec();
querySpec.withKeyConditionExpression("sortKey > :end_date")
                .withValueMap(new ValueMap().withString(":end_date","2021-06-30T07:49:22.000Z"));
items2 = index.query(querySpec);

但是它抛出了一个异常,“不支持QUery键条件”。我不明白这一点,因为在docs中,"<“操作符被描述为常规操作。有人能帮我吗

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-01 15:07:36

DDB 查询()需要一个键条件,其中包括对散列/分区键的相等检查。

您必须提供分区键属性的名称和该属性的单个值。查询返回具有该分区键值的所有项。或者,您可以提供一个排序键属性,并使用比较运算符来细化搜索结果。

换句话说,只有当您有一个复合主键(散列+排序)时,才能真正使用Query()。

如果没有作为表/GSI键的一部分指定的排序键,Query()的作用就像GetItem()使用给定的哈希键返回单个记录一样。

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

https://stackoverflow.com/questions/69407869

复制
相关文章

相似问题

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