英文:
dynamodb enhanced : how to query using SecondaryIndex in java(spring-boot)
问题
我刚刚开始使用 spring-boot-dynamodb enhanced。
aws-skd-java2 中有关于使用分区键进行查询的示例,但我找不到使用 secondaryIndex 进行查询的示例。
请指导如何使用 dynamodb-enhanced 客户端进行 secondaryIndex 查询。
英文:
I just started with spring-boot-dynamodb enhanced.<br/>
aws-skd-java2 has examples to query with partitionkey but I couldn't find examples to query with secondaryIndex. <br/>
Please suggest how to query using secondaryIndex with dynamodb-enhanced client.
答案1
得分: 9
明白解决方案。
DynamoDbIndex<Entity_Class_Name> secIndex = enhancedClient.table(
"table_name",
TableSchema.fromBean(Entity_Class_Name.class)
).index("secondary-index-name");
QueryConditional queryConditional = QueryConditional.keyEqualTo(
Key.builder()
.partitionValue(:value_to_query)
.build()
);
Iterable<Page<Entity_Class_Name>> results = (Iterable<Page<Entity_Class_Name>>)
secIndex.query(
QueryEnhancedRequest.builder()
.queryConditional(queryConditional)
.build()
);
英文:
Figured out the solution.
DynamoDbIndex<Entity_Class_Name> secIndex = enhancedClient.table(
"table_name",
TableSchema.fromBean(Entity_Class_Name.class)
).index("secondary-index-name");
QueryConditional queryConditional = QueryConditional.keyEqualTo(
Key.builder()
.partitionValue(:value_to_query)
.build()
);
Iterable<Page<Entity_Class_Name>> results = (Iterable<Page<Entity_Class_Name>>)
secIndex.query(
QueryEnhancedRequest.builder()
.queryConditional(queryConditional)
.build()
);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论