learner_21
learner_21

Reputation: 613

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?

Upvotes: 8

Views: 9839

Answers (3)

Parvej Chowdhury
Parvej Chowdhury

Reputation: 119

DynamoDBIndexHashKey annotation accepts both single String value and array as index name into it's parameter.

**globalSecondaryIndexName** - Receives a String as index name.
**globalSecondaryIndexNames** -Receives an array of index names. 

So, you may set multiple index names as like below :

@DynamoDBIndexHashKey(attributeName = "placeid" globalSecondaryIndexNames={"placeid-starttime-index", "placeid-endtime-index"})
private String placeid;

Upvotes: 1

learner_21
learner_21

Reputation: 613

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;

Upvotes: 18

Rohit
Rohit

Reputation: 927

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

Upvotes: 2

Related Questions