Mahendra D
Mahendra D

Reputation: 191

dynamodb enhanced : how to query using SecondaryIndex in java(spring-boot)

I just started with spring-boot-dynamodb enhanced.
aws-skd-java2 has examples to query with partitionkey but I couldn't find examples to query with secondaryIndex.
Please suggest how to query using secondaryIndex with dynamodb-enhanced client.

Upvotes: 2

Views: 6819

Answers (1)

Mahendra D
Mahendra D

Reputation: 191

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()
);

Upvotes: 9

Related Questions