dynamodb enhanced: 如何在java(spring-boot)中使用SecondaryIndex进行查询

huangapple go评论69阅读模式
英文:

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&lt;Entity_Class_Name&gt; secIndex = enhancedClient.table(
    &quot;table_name&quot;, 
	TableSchema.fromBean(Entity_Class_Name.class)
).index(&quot;secondary-index-name&quot;);

QueryConditional queryConditional = QueryConditional.keyEqualTo(
    Key.builder()
       .partitionValue(:value_to_query)
       .build()
);

Iterable&lt;Page&lt;Entity_Class_Name&gt;&gt; results = (Iterable&lt;Page&lt;Entity_Class_Name&gt;&gt;) 
secIndex.query(
    QueryEnhancedRequest.builder()
        .queryConditional(queryConditional)
        .build()
);

huangapple
  • 本文由 发表于 2020年9月8日 10:43:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/63786440.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定