Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB - Specify two index names @DynamoDbIndexHashkey globalSecondaryIndexName

I have a DynamoDB table where 2 GSIs have the same hash key but different range key. I am not getting how should I represent 2 index names (globalSecondaryIndexName) in in the @DynamoDBIndexHashKey attribute -

Table
entityid<br/>
placeid<br/>
starttime<br/>
endtime<br/>

GSI 1 - hashkey : placeid, rangekey : starttime<br/>
GSI 2 - hashkey : placeid, rangekey : endtime

@DynamoDBIndexHashKey( attributeName = "placeid" globalSecondaryIndexName= "placeid-starttime-index" )<br>
private String placeid;

How can I specify the second index name here?

like image 514
learner_21 Avatar asked Sep 16 '15 01:09

learner_21


People also ask

How do you query a global secondary index?

Querying a Global Secondary IndexThe query must specify the name of the base table and the name of the index that you want to use, the attributes to be returned in the query results, and any query conditions that you want to apply. DynamoDB can return the results in ascending or descending order.

How many secondary indexes are allowed per DynamoDB table?

Each table in DynamoDB can have up to 20 global secondary indexes (default quota) and 5 local secondary indexes.

Why would you use a secondary index on a DynamoDB table?

Secondary indexes are a critical part of modeling your data in DynamoDB. With a secondary index, you can add additional access patterns to your application without the hassle of maintaining multiple copies of the same data. DynamoDB will handle all replication from the base table to your secondary index.


2 Answers

You have to specify the index names in a String array globalSecondaryIndexNames:

@DynamoDBIndexHashKey( attributeName = "placeid" globalSecondaryIndexNames={  "placeid-starttime-index","placeid-endtime-index"} )
private String placeid;
like image 138
learner_21 Avatar answered Oct 12 '22 02:10

learner_21


The @dynamodbindexhashkey annotation also takes an array for the index names.

Check below link for documentation.

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/dynamodbv2/datamodeling/DynamoDBIndexHashKey.html

like image 44
Rohit Avatar answered Oct 12 '22 02:10

Rohit