简体   繁体   English

使用dynamodb映射器将属性投影到索引

[英]Projecting attributes to indices using dynamodb mapper

I just can't find the way to project selected attributes (not hashkey) into indices using dynamodb mapper annotations. 我只是找不到使用dynamodb映射器注释将所选属性(而不是hashkey)投影到索引中的方法。

Consider an example: 考虑一个例子:

@DynamoDBTable(tableName = "scores")
public class DynaScoreItem {
    @DynamoDBHashKey
    int user;
    @DynamoDBRangeKey
    int level;
    @DynamoDBAttribute
    int score;
    @DynamoDBIndexRangeKey(localSecondaryIndexName = "sort_by_added")
    long added;
}

I just want to add score to "sort_by_added" index. 我只想将分数添加到“ sort_by_added”索引中。 How to do it using annotations? 如何使用注释?

Attribute projections are set on index creation, and not determined by annotations (currently). 属性投影是在索引创建时设置的,并且不由注释决定(当前)。 There is no way to mark attributes as part of an attribute projection with annotations. 无法使用注释将属性标记为属性投影的一部分。 Looking at the Javadoc for the DynamoDBMapper.generateCreateTableRequest(Class<?> clazz) : 查看DynamoDBMapper.generateCreateTableRequest(Class<?> clazz)的Javadoc:

Parse the given POJO class and return the CreateTableRequest for the DynamoDB table it represents. 解析给定的POJO类,并为其表示的DynamoDB表返回CreateTableRequest。 Note that the returned request does not include the required ProvisionedThroughput parameters for the primary table and the GSIs, and that all secondary indexes are initialized with the default projection type - KEY_ONLY. 请注意,返回的请求不包含主表和GSI所需的ProvisionedThroughput参数,并且所有辅助索引均使用默认投影类型KEY_ONLY初始化。

The key part of this is the default projection type - KEY_ONLY . 其中的关键部分是默认的投影类型-KEY_ONLY If you create your table using this API, you would have to specify the projections yourself. 如果使用此API创建表格,则必须自己指定投影。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM